gerwim Posted March 3, 2011 Posted March 3, 2011 Hi guys, So, let's say I have this string: "<OPTION value=6>Test</OPTION>". How can I get the number "6"? There's lot more <options> in there normally. And I want to search for "Test" (so by searching the string for Test, I want 6 as return). Thanks in advance!
saywell Posted March 3, 2011 Posted March 3, 2011 The elegant way is by using a regular expression, but they're hard!Try _StringBetween - using = and >Test as the delimiters. That's assuming there aren't any other = signs in the line.William
gerwim Posted March 3, 2011 Author Posted March 3, 2011 The elegant way is by using a regular expression, but they're hard!Try _StringBetween - using = and >Test as the delimiters. That's assuming there aren't any other = signs in the line.WilliamThere will be like 40 options in the complete string.. =(
JohnOne Posted March 3, 2011 Posted March 3, 2011 heres one way #include <String.au3> $s = "<OPTION value=6>Test</OPTION>" If StringInStr($s,"Test",1) Then $return = _StringBetween($s,"=",">") EndIf MsgBox(0,"",$return[0]) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
gerwim Posted March 3, 2011 Author Posted March 3, 2011 (edited) heres one way #include <String.au3> $s = "<OPTION value=6>Test</OPTION>" If StringInStr($s,"Test",1) Then $return = _StringBetween($s,"=",">") EndIf MsgBox(0,"",$return[0]) Thanks John, but this will not work due to be more then one option. The complete string will be something like this: <OPTION value=6>Test</OPTION><OPTION value=7>Test1</OPTION><OPTION value=8>Derp</OPTION><OPTION value=9>Test3</OPTION><OPTION value=10>Blabla4</OPTION> Edited March 3, 2011 by gerwim
JohnOne Posted March 3, 2011 Posted March 3, 2011 Then the rexexp suggestion above probably the best, I sheepishly work around regexp though. You could do it many different ways using string functions. heres an option using native string* functions $s = "<OPTION value=6>Test</OPTION><OPTION value=7>Test1</OPTION><OPTION value=8>Derp</OPTION><OPTION value=9>Test3</OPTION><OPTION value=10>Blabla4</OPTION>" $a = StringSplit($s,"<OPTION value=",3) $searchstring = "Blabla4" For $i = 0 To Ubound($a) -1 If StringInStr($a[$i],$searchstring,1) Then $return = StringTrimRight($a[$i],10+StringLen($searchstring)) EndIf Next MsgBox(0,"",$return) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Moderators Melba23 Posted March 3, 2011 Moderators Posted March 3, 2011 (edited) gerwim,Do you want just the single digit preceding the "Test" or an array of the digits preceding all the "Test?" elements? M23Edit: Easier than I thought:#include <Array.au3> $sString = "<OPTION value=6>Test</OPTION><OPTION value=7>Test1</OPTION><OPTION value=8>Derp</OPTION><OPTION value=9>Test3</OPTION><OPTION value=10>Blabla4</OPTION>" $iDigit = StringRegExpReplace($sString, "(?i).*value=(\d+)>Test<.*", "$1") MsgBox(0, "Result", $iDigit) $aArray = StringRegExp($sString, "(?i)value=(\d+)>Test", 3) _ArrayDisplay($aArray)And my brain did not hurt too much! Edited March 3, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
gerwim Posted March 3, 2011 Author Posted March 3, 2011 Then the rexexp suggestion above probably the best, I sheepishly work around regexp though. You could do it many different ways using string functions. heres an option using native string* functions $s = "<OPTION value=6>Test</OPTION><OPTION value=7>Test1</OPTION><OPTION value=8>Derp</OPTION><OPTION value=9>Test3</OPTION><OPTION value=10>Blabla4</OPTION>" $a = StringSplit($s,"<OPTION value=",3) $searchstring = "Blabla4" For $i = 0 To Ubound($a) -1 If StringInStr($a[$i],$searchstring,1) Then $return = StringTrimRight($a[$i],10+StringLen($searchstring)) EndIf Next MsgBox(0,"",$return) Thanks, will look into that! gerwim, Do you want just the single digit preceding the "Test" or an array of the digits preceding all the "Test?" elements? M23 No, just single digit, non array.
Moderators Melba23 Posted March 3, 2011 Moderators Posted March 3, 2011 gerwim, Our posts crossed - see my edit above! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
gerwim Posted March 3, 2011 Author Posted March 3, 2011 gerwim,Our posts crossed - see my edit above! M23Damn, awesome. Gotta learn regexes.. Thanks!
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