Jump to content

String Parsing issues


 Share

Recommended Posts

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?

Link to comment
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...

Link to comment
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

Link to comment
Share on other sites

  • Moderators

[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, '')

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...