Sign in to follow this  
Followers 0
modernes

String Parsing issues

4 posts in this topic

Hi,

I am trying to parse a string to extract the first name and last name from a text file, which is formatted as follows:

From: last name, first name

Sent: Tuesday, October 10, 2006 3:07 PM

This is how far I am now:

dim $intReturn

$intReturn = StringInStr(ClipGet(),"From: ",0,1)

Does anyone know how I would grab the last name and first name from the string?

Share this post


Link to post
Share on other sites



Well if your file is exactly:

From: last name, first name (line 1)
Sent: Tuesday, October 10, 2006 3:07 PM (line 2)

then you could use FileReadLine(), then it should return "From: last name, first name"

StringTrimLeft("From: last name, first name", 6) = "last name, first name"

$names = StringSplit("last name, first name", ", ")

$name[1] = Last name

$name[2] = First name

But thats a poor way of doing it...

Share this post


Link to post
Share on other sites

I finally got the solution to the problem - here's what I did if anyone cares to look:

Func parseDesc()

    dim $intReturn, $intLen
    dim $strName, $strEmail, $strMain
    dim $intBegin, $intEnd
    
    $strMain = ClipGet()
    
    $intBegin = StringInStr($strMain,"From: ",0,1) + 6
    $intEnd = StringInStr($strMain,"Sent: ",0,1)-2
    
    $strName = StringSplit(StringMid($strMain,$intBegin, $intEnd-$intBegin),",")

        EndFunc

So the name would be $strName[1], for the last name and $strName[2], would be for the first name

Share this post


Link to post
Share on other sites

[0] = Last Name | [1] = First Name Unless you use 3 as a flag, then it will return all of the occurrences: And you'll need to separate with a Loop stepping 2.

The #include <array.au3> and the _ArrayDisplay() are just to let you see the result:

#include <array.au3>
$str = "From: last name, first name"
$a = StringRegExp($str, '\w*:\s(\w*\s\w*),\s(\w*\s\w*)', 1)
_ArrayDisplay($a, '')

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0