Sign in to follow this  
Followers 0
gcue

which function to capture string

34 posts in this topic

i have a file that has this following line

Full Name Jones, Bob

i want to capture Jones, Bob and turn it into Bob Jones

im not sure which function i should use to search for this.

Share this post


Link to post
Share on other sites



awesome.. how does it know to look in which filename?

stringinfile?

$String = "Full Name Jones, Bob"

$array = StringRegExp($string,"(?:Full Name )(.*),.(.*)",3)

MsgBox(0,"",$array[1] & " " & $array[0])

If IsArray($array) Then
    For $X = 0 to Ubound($array)-1
        ConsoleWrite($array[$X] & @CRLF)
    Next
EndIf

Share this post


Link to post
Share on other sites

Huh? You said this was for one line in a file. This is meant for a file that has been split into an array.

Share this post


Link to post
Share on other sites

yes its one of the lines in a file. but how does it know which file to look at?

Huh? You said this was for one line in a file. This is meant for a file that has been split into an array.

Share this post


Link to post
Share on other sites

yes its one of the lines in a file. but how does it know which file to look at?

You use FileRead() or _FileReadToArray.

Share this post


Link to post
Share on other sites

instead of stringregexp?

You use FileRead() or _FileReadToArray.

Share this post


Link to post
Share on other sites

Are you saying you have a file, but you don't know which file it is? Do you want to search a directory for the file or what? You need to explain yourself better.

Share this post


Link to post
Share on other sites

i have a text file (file.txt) that has multiple lines. i want to capture the name of the person from this line:

Full Name Jones, Bob

and use the array made by a stringsplit? to get Bob Jones

Share this post


Link to post
Share on other sites

;$String = FileRead("somefile.txt")

;Delete the following lines when you're done testing
$String = ""
$String &= "This is a line" & @CRLF
$String &= "Full Name Jones, Bob" & @CRLF
$String &= "This is another line" & @CRLF

$array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3)

MsgBox(0,"",$array[1] & " " & $array[0])

If IsArray($array) Then
    For $X = 0 to Ubound($array)-1
        ConsoleWrite($array[$X] & @CRLF)
    Next
EndIf

Share this post


Link to post
Share on other sites

Then just use weaponx's code in a loop through your file line array.

#include <File.au3>
Global $aFilelines, $sLine, $aResult

If _FileReadToArray("file.txt", $aFilelines) = 1 Then
    For $sLine In $aFilelines
        $aResult = StringRegExp($sLine,"(?:Full Name )(.*),.(.*)",3)
        If @error = 0 Then
            MsgBox(0, "Full Name", $aResult[1] & " " & $aResult[0])
            ExitLoop
        EndIf
    Next
EndIf

Share this post


Link to post
Share on other sites

perfect thanks for your help fellas!

Share this post


Link to post
Share on other sites

hey weapon. just curious.

what if i want to use this for multiple files.. and the name is diffferent (filename the same)? is there a way to account for some type of wildcard?

;$String = FileRead("somefile.txt")

;Delete the following lines when you're done testing
$String = ""
$String &= "This is a line" & @CRLF
$String &= "Full Name Jones, Bob" & @CRLF
$String &= "This is another line" & @CRLF

$array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3)

MsgBox(0,"",$array[1] & " " & $array[0])

If IsArray($array) Then
    For $X = 0 to Ubound($array)-1
        ConsoleWrite($array[$X] & @CRLF)
    Next
EndIf

Share this post


Link to post
Share on other sites

what if i want to use this for multiple files.. and the name is diffferent (filename the same)?

That doesn't make sense. Multiple files with the same filename? How is that possible?

Share this post


Link to post
Share on other sites

well not same filename.. but im going to handle multiple filenames that im handlign with the same $var

heh sorry

Share this post


Link to post
Share on other sites

well not same filename.. but im going to handle multiple filenames that im handlign with the same $var

heh sorry

Then you use:

$root = "c:\"
$FileList = _FileListToArray($root,"*.txt")
For $X = 0 to $FileList[0]
$FileName = $FileList[$X]
FileRead($root & $FileName)
etc...

This is simple stuff.

Share this post


Link to post
Share on other sites

im not having the problem wtih the different files..

im having a problem witht he different names given in

Full Name x, y

by each file =)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

im not having the problem wtih the different files..

im having a problem witht he different names given in

Full Name x, y

by each file =)

I don't understand, the original function I posted takes "Full Name x, y" and returns "y x".

Edited by weaponx

Share this post


Link to post
Share on other sites

Huh? You said this was for one line in a file. This is meant for a file that has been split into an array.

No need to split the file content into an array if you use the multiline option on the regular expression (?m)

Share this post


Link to post
Share on other sites

right but it only works if the name is Maxson, Joshua

these files would have different names in each one

heres what i got:

im going to use the name i find in $initials_AD_file as part of a URL

$String = FileRead($initials_AD_file)

$String = ""

$String &= "This is a line" & @CRLF

$String &= "Full Name Jones, Bob" & @CRLF

$String &= "This is another line" & @CRLF

$array = StringRegExp($string,"(?:Full Name.)(.*),.(.*)\r\n",3)

;MsgBox(0,"",$array[1] & " " & $array[0])

If IsArray($array) Then

For $X = 0 to Ubound($array)-1

ConsoleWrite($array[$X] & @CRLF)

Next

EndIf

$scexe = @ProgramFilesDir & "\intern~1\iexplore.exe"

$scarg = "http://invlaolns01.capgroup.com/names.nsf/85255e01001356a8852556d4006ca21c?SearchView&&SearchOrder=4&Query=FIELD+Members=" & $array[1] & "%20" & $array[0]

$scdest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "_NOTES.lnk"

FileCreateShortcut( $scexe, $scdest, "", $scarg)

I don't understand, the original function I posted takes "Full Name x, y" and returns "y x".

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