dion Posted July 16, 2010 Posted July 16, 2010 (edited) Hi Folks, I had been searching online for some help but failed. I would like to my script to find the word after a specific word, but my script it does not return the field after it. My scripts look something like this: $FileName = @ScriptDir & "\TEST.txt" $Backup = @ScriptDir & "\TEST-BCK.txt" FileCopy ($FileName, $Backup) $FileContents = FileRead($FileName) $Results = StringSplit( "Password", ":",2) Msgbox(0,"Status","Password: " & $Results) What I wish to achieve is that it would search for this string call password in this particular file and then it would return the filed after it. The text file looks something like this: ================================================== Name : Test123 Application : MS Outlook 2002/2003/2007 Email : test123@isp.com.sg Server : pop.isp.com.sg Type : POP3 User : user123 Password @ssw0rd Profile : Outlook ================================================== Any help would be appreciated, thank you in advance. Edited July 16, 2010 by dion
rosaz Posted July 16, 2010 Posted July 16, 2010 You could try searching between the ":" and the character after the password- maybe something like this?: $FileName = @ScriptDir & "\TEST.txt" $Backup = @ScriptDir & "\TEST-BCK.txt" FileCopy ($FileName, $Backup) $FileContents = FileRead($FileName) $passwordloc = StringinStr($FileContents, "Password"); finds the number of the first character of password $passwordfinloc = $passwordloc + 9 ;find the first character after "Password:" $profileloc = StringinStr($FileContents, "Profile") $userpassword = StringMid($FileContents, $passwordfinloc, $profileloc - $passwordfinloc) ;finds the characters between the two
Ascend4nt Posted July 16, 2010 Posted July 16, 2010 (edited) $sBuffer="Name : Test123"&@CRLF& _ "Application : MS Outlook 2002/2003/2007"&@CRLF& _ "Email : test123@isp.com.sg"&@CRLF& _ "Server : pop.isp.com.sg"&@CRLF& _ "Type : POP3"&@CRLF& _ "User : user123"&@CRLF& _ "Password :P@ssw0rd"&@CRLF& _ "Profile : Outlook" $aMatch=StringRegExp($sBuffer,"Password\s*\:\s*(.*)",1) If Not @error Then ConsoleWrite("Match:"&$aMatch[0]&@CRLF) *edit: code tags Edited July 16, 2010 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
dion Posted July 18, 2010 Author Posted July 18, 2010 Thanks folks, I had tried and it works. Thank you so much. Ascend4nt>> I did not use your as I do not understand it, my apologies as I'm very new with scripting. Could I ask what is the usage \s* ?
GEOSoft Posted July 18, 2010 Posted July 18, 2010 Thanks folks, I had tried and it works. Thank you so much.Ascend4nt>> I did not use your as I do not understand it, my apologies as I'm very new with scripting. Could I ask what is the usage \s* ?In a regular expression it means match any spaces that may or may not appear before and after the colon. It would match any of the follwing plus any where multiple spaces were used in the same positionsPassword:mypasswordPassword: mypasswordPassword : mypasswordPassword :mypassword George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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