simpleinventor Posted August 6, 2006 Share Posted August 6, 2006 (edited) Say "a.txt" has some lines of text, but some lines are just "enter" (CR\LF). The first msg box should say the total number of lines there are, and the rest should give the line number of the lines without only whitespace. The idea is to skip blank lines. Any thoughts? #include <file.au3> $toolBarAddress = @DesktopDir & "\a.txt" $lineCount = _FileCountLines($toolBarAddress) MsgBox(0,"File Line Count", "The count: " & $lineCount) $fileHandle = FileOpen($toolBarAddress, 0) For $i = 1 to $lineCount $tempLineRead = FileReadLine($fileHandle, $i) If StringIsSpace($tempLineRead) Then ContinueLoop MsgBox(0, "The value of $i is:", $i) Next FileClose($fileHandle) Edited August 6, 2006 by simpleinventor Link to comment Share on other sites More sharing options...
Paulie Posted August 6, 2006 Share Posted August 6, 2006 Say "a.txt" has some lines of text, but some lines are just "enter" (CR\LF). The first msg box should say the total number of lines there are, and the rest should give the line number of the lines without only whitespace. The idea is to skip blank lines. Any thoughts? #include <file.au3> $toolBarAddress = @DesktopDir & "\a.txt" $lineCount = _FileCountLines($toolBarAddress) MsgBox(0,"File Line Count", "The count: " & $lineCount) $fileHandle = FileOpen($toolBarAddress, 0) For $i = 1 to $lineCount $tempLineRead = FileReadLine($fileHandle, $i) If StringIsSpace($tempLineRead) Then ContinueLoop MsgBox(0, "The value of $i is:", $i) Next FileClose($fileHandle)'StringStripWS' 'StringStripCR' Right here Link to comment Share on other sites More sharing options...
Valuater Posted August 6, 2006 Share Posted August 6, 2006 maybe #include <GUIConstants.au3> #include <File.au3> $toolBarAddress = @DesktopDir & "\a.txt" $lineCount = _FileCountLines($toolBarAddress) MsgBox(0,"File Line Count", "The count: " & $lineCount) $fileHandle = FileOpen($toolBarAddress, 0) For $i = 1 to $lineCount $tempLineRead = FileReadLine($fileHandle, $i) If StringIsSpace($tempLineRead) Then ContinueLoop If $tempLineRead = "" Then ContinueLoop MsgBox(0, "The value of $i is:", $i) Next FileClose($fileHandle) 8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 6, 2006 Moderators Share Posted August 6, 2006 Why not just:For $i = 1 to $lineCount $tempLineRead = FileReadLine($fileHandle, $i) If StringStripWS($tempLineRead, 8) <> '' Then MsgBox(0, "The value of $i is:", $i) Next 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. Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 (edited) $toolBarAddress = @DesktopDir & "\a.txt" $lineCount = 0 $emptylines = 0 $fileHandle = FileOpen($toolBarAddress, 0) While 1 $line = FileReadLine($fileHandle) If @error = -1 Then ExitLoop $linecount = $linecount + 1 If StringLen($line) = 0 Then $emptylines = $emptylines + 1 Wend FileClose($fileHandle) MsgBox(4096,"INFO","Lines: " & $linecount & " Empty lines: " & $emptylines) Cheers Kurt Edited August 6, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 6, 2006 Moderators Share Posted August 6, 2006 $toolBarAddress = @DesktopDir & "\a.txt" $lineCount = 0 $emptylines = 0 $fileHandle = FileOpen($toolBarAddress, 0) While 1 $line = FileReadLine($fileHandle) If @error = -1 Then ExitLoop $linecount = $linecount + 1 If StringLen($line) = 0 Then $emptylines = $emptylines + 1 Wend FileClose($fileHandle) MsgBox(4096,"INFO","Lines: " & $linecount & " Empty lines: " & $emptylines) Cheers KurtA space still gives the illusion of a non-empty line if your using StringLen() and all there is on that line is a space. 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. Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 A space still gives the illusion of a non-empty line if your using StringLen() and all there is on that line is a space.That's right, but his assumption was: "but some lines are just "enter" (CR\LF)." With just @CRLF on a line StringLen() will return 0. My code only works for the special requirements he mentioned in the first post.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Valuater Posted August 6, 2006 Share Posted August 6, 2006 Why not just:For $i = 1 to $lineCount $tempLineRead = FileReadLine($fileHandle, $i) If StringStripWS($tempLineRead, 8) <> '' Then MsgBox(0, "The value of $i is:", $i) NextoÝ÷ Ûú®¢×°)赫¢+Ø(¥¹±Õ±Ðí¥±¹ÔÌÐì)¥´ÀÌØí±¥¹ ½Õ¹Ð((ÀÌØíѽ½± ÉÉÍÌôÍѽÁ¥ÈµÀìÅÕ½ÐìÀäÈí¹ÑáÐÅÕ½Ðì)}¥±IQ½ÉÉä ÀÌØíѽ½± ÉÉÍÌ°ÀÌØí±¥¹ ½Õ¹Ð¤()5Í ½à À°ÅÕ½Ðí¥±1¥¹ ½Õ¹ÐÅÕ½Ðì°ÅÕ½ÐíQ¡½Õ¹ÐèÅÕ½ÐìµÀìÀÌØí±¥¹ ½Õ¹ÑlÁt¤()½ÈÀÌØí¤ôÄѼÀÌØí±¥¹ ½Õ¹ÑlÁt(%MÑÉ¥¹MÑÉ¥Á]L ÀÌØí±¥¹ ½Õ¹ÑlÀÌØí¥t°à¤±ÐìÐìÌäìÌäìQ¡¸5Í ½à À°ÅÕ½ÐíQ¡Ù±Õ½ÀÌØí¤¥ÌèÅÕ½Ðì°ÀÌØí¤¤)9áÐ( if your going to re-write the script 8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 6, 2006 Moderators Share Posted August 6, 2006 why not #include <File.au3> Dim $lineCount $toolBarAddress = @DesktopDir & "\a.txt" _FileReadToArray($toolBarAddress, $lineCount) MsgBox(0,"File Line Count", "The count: " & $lineCount[0]) For $i = 1 to $lineCount[0] If StringStripWS($lineCount[$i], 8) <> '' Then MsgBox(0, "The value of $i is:", $i) Next if your going to re-write the script 8)lol@both of you... I was wondering why he wasn't using _FileReadToArray() but whenever I suggest an easier way, people always take the long way anyway. 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. Link to comment Share on other sites More sharing options...
simpleinventor Posted August 6, 2006 Author Share Posted August 6, 2006 Does anyone know why my code doesn't work? I'd really like to ignore a line with that contains only whitespace (meaning all kinds of whitespace.) Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 Does anyone know why my code doesn't work? I'd really like to ignore a line with that contains only whitespace (meaning all kinds of whitespace.)wrong logic. $i will allways be $lineCount, so you need another variable to store the empty lines. Next Problem StringIsSpace does not detect plain empty lines, only @CRLF (don't know why!).CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
MHz Posted August 6, 2006 Share Posted August 6, 2006 (edited) FileReadLine() strips carriage return characters from end of lines. Therefore, any lines that were empty lines, contain no end of line whitespace types after using FileReadLine(). This means that StringIsSpace will return 0 in checking a value of nothing. Edited August 6, 2006 by MHz Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 FileReadLine() strips carriage return characters from end of lines.Therefore, any lines that were empty lines, contain no end of line whitespace types after using FileReadLine(). This means that StringIsSpace will return 0 in checking a value of nothing.yep, you're absolutely right! I did not remember that "stripping thing" CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * 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