gcue Posted May 30, 2008 Share Posted May 30, 2008 i have a file that has this following lineFull Name Jones, Bobi want to capture Jones, Bob and turn it into Bob Jonesim not sure which function i should use to search for this. Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 $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 Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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 Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 Huh? You said this was for one line in a file. This is meant for a file that has been split into an array. Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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. Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 yes its one of the lines in a file. but how does it know which file to look at?You use FileRead() or _FileReadToArray. Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 instead of stringregexp?You use FileRead() or _FileReadToArray. Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 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. Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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, Boband use the array made by a stringsplit? to get Bob Jones Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 ;$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 Link to comment Share on other sites More sharing options...
zorphnog Posted May 30, 2008 Share Posted May 30, 2008 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 Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 perfect thanks for your help fellas! Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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 Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 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? Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 well not same filename.. but im going to handle multiple filenames that im handlign with the same $var heh sorry Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 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. Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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 =) Link to comment Share on other sites More sharing options...
weaponx Posted May 30, 2008 Share Posted May 30, 2008 (edited) im not having the problem wtih the different files..im having a problem witht he different names given in Full Name x, yby each file =)I don't understand, the original function I posted takes "Full Name x, y" and returns "y x". Edited May 30, 2008 by weaponx Link to comment Share on other sites More sharing options...
Sheri Posted May 30, 2008 Share Posted May 30, 2008 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) Link to comment Share on other sites More sharing options...
gcue Posted May 30, 2008 Author Share Posted May 30, 2008 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". Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now