dexto Posted April 3, 2010 Posted April 3, 2010 $txt = "<a> useless text <b> 5 users </a" ConsoleWrite(StringInStr($txt, '>', 1, -1, 5)&@CRLF) Output: 3 How is that possible? P.S. Using AutoIt v3.3.6.0
jchd Posted April 3, 2010 Posted April 3, 2010 $txt = "<a> useless text <b> 5 users </a"ConsoleWrite(StringInStr($txt, '>', 1, -1, 5)&@CRLF)This is correct: return the 1-based position of the first occurence of '>' searching from right to left begining at position 5 using a case-sensitive compare. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
dexto Posted April 3, 2010 Author Posted April 3, 2010 $txt = "<a> useless text <b> 5 users </a"ConsoleWrite(StringInStr($txt, '>', 1, -1, 5)&@CRLF)This is correct: return the 1-based position of the first occurence of '>' searching from right to left begining at position 5 using a case-sensitive compare.Starting from the right to left first occurrence of the string '>' is not 3 but 20.. so, function should return 20?Like so: StringInStr($txt, '>', 1, -1)Output: 20
Moderators big_daddy Posted April 3, 2010 Moderators Posted April 3, 2010 You are telling it to start searching from position 5 which would be the "u" in useless. The first occurrence from right to left from there is the third position in the string.
jchd Posted April 3, 2010 Posted April 3, 2010 You omit starting at position 5. So Position 5 is your rightmost position. Equivalent code: $cmp = StringLeft($txt, 5) $cmp = _StringReverse($cmp) $res = StringLen($cmp) - StringInStr($cmp, '>') + 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
dexto Posted April 3, 2010 Author Posted April 3, 2010 (edited) oh.... now i see! Offset of the string is also direction dependent. Edit: never mind I don't see. Edited April 3, 2010 by dexto
dexto Posted April 3, 2010 Author Posted April 3, 2010 You are telling it to start searching from position 5 which would be the "u" in useless. The first occurrence from right to left from there is the third position in the string. $txt = "<a> useless text <b> 5 users </a" ConsoleWrite(StringInStr($txt,'>',0,-1,5)&@CRLF) Its not 3rd in this case... yet output is 3
dexto Posted April 3, 2010 Author Posted April 3, 2010 You omit starting at position 5. So Position 5 is your rightmost position. Equivalent code: $cmp = StringLeft($txt, 5) $cmp = _StringReverse($cmp) $res = StringLen($cmp) - StringInStr($cmp, '>') + 1 5 is not the rightmost position, its "start [optional] The starting position of the search. "
dexto Posted April 3, 2010 Author Posted April 3, 2010 In other words "negative occurrence to search from the right side" invalidates the "start" and "count" of the function and "finds first occurrence" instead. So: StringInStr($txt,'>',0,-1,5) ; Same as StringInStr($txt,'>',0,1) ; or StringInStr($txt,'>')
James Posted April 3, 2010 Posted April 3, 2010 First word that comes to mind with your last FOUR posts? EDIT.Thanks. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
dexto Posted April 3, 2010 Author Posted April 3, 2010 (edited) In fact.... $txt = "<a> useless text <b> 5 users </a" ConsoleWrite(StringInStr($txt,'>',0,-1,6,8)&@CRLF) ConsoleWrite(StringInStr($txt,'>',0,-1,5)&@CRLF) ConsoleWrite(StringInStr($txt,'>',0,-1,5)&@CRLF) ConsoleWrite(StringInStr($txt,'>',0,1)&@CRLF) ConsoleWrite(StringInStr($txt,'>')&@CRLF) Are all the same. P.S. Sorry for multiple concurrent posts... Edited April 3, 2010 by dexto
jchd Posted April 3, 2010 Posted April 3, 2010 (edited) No, you still don't get it. The code is equivalent to what I gave (except that I forgot the case-isensitive parameter, which is irrelevant for this example).Here is the match at 3 (down arrow)12↓<a> useless text <b> 5 users </a1234↲ start comparing here, to the leftEdit: argh, formatting once again destroyed. Another try. Edited April 3, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jchd Posted April 3, 2010 Posted April 3, 2010 Replying to "all the same": in this particular case, yes, but if one changes a little the input: $txt = "a>us>eless>text <b> 5 users </a" ConsoleWrite(StringInStr($txt,'>',0,-1,12,8)&@CRLF) ConsoleWrite(StringInStr($txt,'>',0,-1,5)&@CRLF) ConsoleWrite(StringInStr($txt,'>',0,1)&@CRLF) ConsoleWrite(StringInStr($txt,'>')&@CRLF) The last two statements are indeed exactly identical (default values) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Moderators big_daddy Posted April 3, 2010 Moderators Posted April 3, 2010 (edited) $txt = "Why is this so hard for you to understand?" ; Position 5 is the "i" in is ; This returns 3 because the "y" in why is the first occurrence from right to left of the "i" in is ConsoleWrite(StringInStr($txt, 'y', 1, -1, 5) & @CRLF) ; Position 10 is the "i" in this ; This returns 0 because StringInStr does not wrap back around and search the remainder of the string ConsoleWrite(StringInStr($txt, 'd', 1, -1, 10) & @CRLF) ; Position 15 is the space between so and hard ; This returns 14 because the "o" in so is the first occurrence from right to left of the space between so and hard ConsoleWrite(StringInStr($txt, 'o', 1, -1, 15) & @CRLF) Edited April 3, 2010 by big_daddy
dexto Posted April 3, 2010 Author Posted April 3, 2010 (edited) He... well.. I missed that count was counting down the characters from the start not the parameters to point the scope of the search (like StringMid would). Thank you guys for the patience! Big props for that! Edited April 3, 2010 by dexto
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