Alterego Posted March 19, 2005 Share Posted March 19, 2005 I could use some assistance with string matching text that contains many returns. A good example is the source to this page. If you scroll down you will see there are many returns alaExample:<td> <font color="green">FAST</font>I think one problem is that I don't fully understand the difference between @CRLF, @CR, and @LF, how to tell what is being used, and which is typically used in any given circumstance. The help file doesn't really touch on that. I typically use @CRLF. I am also not sure if StringStripCR also strips @LF and @CRLF. So suppose I want to match the previous string (specifically the word FAST), - I am going to have to use the line breaks/feeds/returns to assist in identification - both before the occurance of the word and after. Can someone help me with that? This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
therks Posted March 19, 2005 Share Posted March 19, 2005 (edited) In my experience: If it was written in Windows, then "line breaks" consist of a carriage return (@CR) and a line feed (@LF) Otherwise a line break consists of just a line feed. This is why (if you've seen this happen) sometimes you view the source to a webpage in Windows, it opens in Notepad, and it all appears to be on one line. Only the line feed character is present and Notepad relies on having the carriage return as well, or else it does not percieve a new line. Edit: Also, StringStripCR only strips carriage returns. So what you can do, is something like strip all the @CR from your source, then just use the @LF to try and find your text. Something like this: $pageSource = "where you get the source for the page from" $pageSource = StringStripCR($pageSource) $compareLine = "<td>" & @LF & @LF & "<font color=""green"">FAST</font>" StringInStr($pageSource, $compareLine) Or however it is you want to do it. Edited March 19, 2005 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Alterego Posted March 19, 2005 Author Share Posted March 19, 2005 (edited) thanks Saunders i wrote a udf $test = 'do' & @CRLF & 're' & @CR & 'me' & @LF & 'fa' & @CRLF & 'so' & @CR & 'la' & @LF & 'ti' & @CRLF & 'do' MsgBox(1,"",_FindNewLine($test,'re','me')) Func _FindNewLine( $nlString,$nlBefore,$nlAfter ) $nlTypes = StringSplit(@CRLF & ',' & @CR & ',' & @LF,',') For $nlLoop = 1 to 3 $nlSearch = StringInStr($nlString,$nlbefore & $nlTypes[$nlLoop] & $nlAfter) If $nlSearch <> 0 Then Return $nlSearch EndIf Next EndFunc trying to think of an easy way to do the match even if there are more than one in a row..but it works for just one so far Edited March 19, 2005 by Alterego This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
Alterego Posted March 19, 2005 Author Share Posted March 19, 2005 woohoo! i did it! $test = 'do' & @CRLF & 're' & @CR & @CR & @CR & @CR & 'me' & @LF & 'fa' & @CRLF & 'so' & @CR & 'la' & @LF & 'ti' & @CRLF & 'do' MsgBox(1,"",_FindNewLine($test,'re',5,'me',5)) Func _FindNewLine( $nlString,$nlBefore,$nlMaxOccurBefore,$nlAfter,$nlMaxOccurAfter ) $nlTypes = StringSplit(@CRLF & ',' & @CR & ',' & @LF,',') For $nlLoop = 1 to 3 For $nlLoop2 = 1 to $nlMaxOccurBefore + $nlMaxOccurAfter $nlSearch = StringInStr($nlString,$nlbefore & $nlTypes[$nlLoop] & $nlAfter) If $nlSearch <> 0 Then Return $nlSearch EndIf $nlTypes[$nlLoop] = $nlTypes[$nlLoop] & $nlTypes[$nlLoop] Next Next EndFunc This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
Alterego Posted March 21, 2005 Author Share Posted March 21, 2005 ah-hah!CR LF: Windows CR: Macintosh LF: UnixCan we put this in the help file? This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
therks Posted March 22, 2005 Share Posted March 22, 2005 So Mac's only use a carriage return? Odd... My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
steveR Posted March 22, 2005 Share Posted March 22, 2005 I way I always remembered it was: for windows CR comes before LF, alphabetically Mac comes before Unix CR comes before LF err, something like that AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. 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