gcue Posted December 29, 2008 Posted December 29, 2008 hello, i have a variable ($s1Text) that equals this: Quote " Cancel Searchresult No Documents Found " I'm not sure how to make this condition true: if $s1Text = "" then MsgBox(0, "Body Text", "true") EndIf i tried to count the number of line breaks and substituting them with & Chr(13) - but i couldnt get that to work...
picaxe Posted December 29, 2008 Posted December 29, 2008 Maybe something like if StringRegExpReplace($s1Text, "\s", "") = "" then MsgBox(0, "Body Text", "true") EndIf
gcue Posted December 29, 2008 Author Posted December 29, 2008 that didnt seem to work =/ any other ideas?
Valuater Posted December 29, 2008 Posted December 29, 2008 *** TESTED OK *** $string = fileread("Tester.txt") $string = StringReplace($string, @CRLF, "") MsgBox(0x0, @extended, $string) 8)
GEOSoft Posted December 29, 2008 Posted December 29, 2008 Just a variation on Valuaters code that will only get the blank line count. $string = fileread("Tester.txt") StringRegExpReplace($string, "(?m:^)\v", "") MsgBox(4096, "Results", "There are " & @Extended & " empty lines") George Reveal hidden contents 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!"
Valuater Posted December 29, 2008 Posted December 29, 2008 gcue said: brilliant! that works thanks budWelcome@GEO ... 8)
GEOSoft Posted December 29, 2008 Posted December 29, 2008 Valuater said: Welcome @GEO ... 8)Hope you realize that technically we are both incorrect. To get the count only the replace string should be the same as the search string. In your case $string = StringReplace($string, @CRLF, @CRLF) and in mine StringRegExpReplace($string, "(?m:^)(\v)", "$1") Also, using the regexp, it will get empty lines no matter what vertical character was used for the line terminator, char() 10 through 13 George Reveal hidden contents 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!"
PsaltyDS Posted December 29, 2008 Posted December 29, 2008 I think y'all been into the Egg Nogg and are over-thinking it a bit: If StringStripWS($s1Text, 8) = "" Then MsgBox(0, "Body Text", "true") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
GEOSoft Posted December 29, 2008 Posted December 29, 2008 (edited) PsaltyDS said: I think y'all been into the Egg Nogg and are over-thinking it a bit: If StringStripWS($s1Text, 8) = "" Then MsgBox(0, "Body Text", "true") EndIf Everybody is missing the point that the OP asked for a COUNT of the blank lines. Edit: Actually I'm wrong In that. He just wants to replace all of the line breaks with Chr(13). Therefore my code should have been $string = fileread("Tester.txt") $string = StringRegExpReplace($string, "\r\n|\v", Chr(13)) That will replace any vertical WS character with Chr(13) and it wont matter if the line actually ended with @CRLF, @CR, @LF or a vertical tab or Form Feed Edited December 29, 2008 by GEOSoft George Reveal hidden contents 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!"
PsaltyDS Posted December 29, 2008 Posted December 29, 2008 GEOSoft said: Everybody is missing the point that the OP asked for a COUNT of the blank lines. Edit: Actually I'm wrong In that. He just wants to replace all of the line breaks with Chr(13). Therefore my code should have been $string = fileread("Tester.txt") $string = StringRegExpReplace($string, "\r\n|\v", Chr(13)) That will replace any vertical WS character with Chr(13) and it wont matter if the line actually ended with @CRLF, @CR, @LF or a vertical tab or Form Feed Well, it would be best if gcue answered for himself, but the code he posted in post #1 was a test for a null string, that he seemed to want to be true even if there were multiple blank lines. The rest was about achieving that, which StringStripWS() does nicely. You've just been around Ron long enough that every problem looks like a RegExp! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
GEOSoft Posted December 29, 2008 Posted December 29, 2008 PsaltyDS said: You've just been around Ron long enough that every problem looks like a RegExp! Are you syaing I've been brainwashed? Probably true. George Reveal hidden contents 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!"
PsaltyDS Posted December 29, 2008 Posted December 29, 2008 (edited) GEOSoft said: Are you syaing I've been brainwashed? Probably true. Func _SmOke_N_Reeducation() $GEOSoft = StringRegExpReplace($GEOSoft, "[[:reality:]]", $NewSpeak) EndFunc Edited December 29, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Moderators SmOke_N Posted December 29, 2008 Moderators Posted December 29, 2008 PsaltyDS said: Func _SmOke_N_Reeducation() $GEOSoft = StringRegExpReplace($GEOSoft, "[[:reality:]]", $NewSpeak) EndFunc You've obviously not seen this rare occasion : http://www.autoitscript.com/forum/index.ph...st&p=622128 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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