Ace08 Posted September 29, 2010 Share Posted September 29, 2010 hi guys i was given a task by my boss to create a program that will split a string into a 3 categories namely date, cur, and amount... so as part of my training with autoit i've decided to create the program using it the string somehow looks like this :78G:092910USD8000.00 where :78G: is the tag date = 092910 cur = USD Amt = 8000.00 i have this code below $Tag2 = StringInStr($line , ":78G:") if $Tag2 > 0 then $Srch = StringInStr($line , "USD") if $Srch > 0 then $DCI = StringSplit($line, "USD") $Cur = "USD" $Date = StringRight($DCI[1], 6) $Amt = $DCI[2] MsgBox(0,'',$Date) MsgBox(0,'',$Cur) MsgBox(0,'',$Amt) endif endif The output came as expected exept for the amount which gives a blank variable, i know my coding is kinda messed up... Work smarter not harder.My First Posted Script: DataBase Link to comment Share on other sites More sharing options...
Mison Posted September 29, 2010 Share Posted September 29, 2010 (edited) Change $Amt = $DCI[2] to $Amt = $DCI[4]. Use _ArrayDisplay($DCI) to check on array returned by StringSplit function. To use _ArrayDisplay, you must include Array UDF -> #include <Array.au3> Edited September 29, 2010 by Mison Hi ;) Link to comment Share on other sites More sharing options...
Ace08 Posted September 29, 2010 Author Share Posted September 29, 2010 thanks Mison its now working but im a bit confused, ive splited the string via USD term so i tought it would just return 2 array values so why is it 4? sorry but i just want to know Work smarter not harder.My First Posted Script: DataBase Link to comment Share on other sites More sharing options...
wakillon Posted September 29, 2010 Share Posted September 29, 2010 (edited) Try $DCI = StringSplit($line, "USD", 1) and you'll see array with 2 values ! ( flag = 1, entire delimiter string is needed to mark the split ) Edited September 29, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
GEOSoft Posted September 29, 2010 Share Posted September 29, 2010 (edited) $sLine = "78G:092910USD8000.00" $aLine = StringRegExp($sLine, "(?i)78G:(\d+)(\D+)([\d.]+)", 1) If NOT @Error Then $sDate = $aLine[0] $sCurr = $aLine[1] $sAmount = $aLine[2] MsgBox(0, "Result", "date: " & $sDate & @CRLF & "Currency: " & $sCurr & @CRLF & "Amount: $" & $sAmount) EndIf Edit: minor cosmetic change to MsgBox() Edited September 29, 2010 by GEOSoft 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!" Link to comment Share on other sites More sharing options...
Ace08 Posted September 29, 2010 Author Share Posted September 29, 2010 Thanks guys i was just curious as to why $Amt = $DCI[2] to $Amt = $DCI[4]@wakillon Thanks i've also tried your code and it worked @GEOSoftThanks also for the code its also working but i rather not have regular expression for the moment it's kinda advance for me since im just starting to learn autoit Work smarter not harder.My First Posted Script: DataBase Link to comment Share on other sites More sharing options...
Mison Posted September 29, 2010 Share Posted September 29, 2010 thanks Mison its now working but im a bit confused, ive splited the string via USD term so i tought it would just return 2 array values so why is it 4? sorry but i just want to know So do I. The best explanation I can think of is that you're using more than 1 char to split a string, so it returns empty matches. Try Flag = 1: $line = "78G:092910USD8000.00" $Tag2 = StringInStr($line , "78G") if $Tag2 > 0 then $Srch = StringInStr($line , "USD") if $Srch > 0 then $DCI = StringSplit($line, "USD",1); entire delimiter string is needed to mark the split $Cur = "USD" $Date = StringRight($DCI[1], 6) $Amt = $DCI[2] MsgBox(0,'',$Date) MsgBox(0,'',$Cur) MsgBox(0,'',$Amt) endif endif It works. Try this too.. #include <array.au3> $line = "aaa(bbb)ccc" $array = StringSplit($line,"()") _ArrayDisplay($array) Hi ;) 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