CrewXp Posted April 11, 2006 Posted April 11, 2006 I have a question. I have a program I'm making that copies and displays txt that's not in a comment in a msg box. Text that's commented has lines starting with a "#". But one of my un-commented lines has a "#" in it, in the code part. (It's a hex color). Is there any way to make my while loop to run with this?? This is some of what I have: $mystring="" $line = FileReadLine($file,$linenumber) While (StringInStr($line, "#"))>0 $linenumber=$linenumber+1 $line = FileReadLine($file,$linenumber) WEnd While (StringInStr($line, "#"))=0 If StringLen(StringStripWS($line, 3))>0 Then $mystring=$mystring&@LF&$line $linenumber=$linenumber+1 $line = FileReadLine($file,$linenumber) WEnd Msgbox(0,"My Current Code",$mystring Here is part of my txt file it reads from: # #-----[ Original Code ]------------------------------------------ # if(!empty($topicimage)) { echo "<table border=\"0\" width=\"98%\" align=\"center\"><tr><td>\n"; echo "<a href=\"modules.php?name=News&new_topic=$topic\"><img src=\"$tipath$topicimage\" alt=\"$topictext\" border=\"0\" align=\"right\"></a>"; } # #-----[ Replaced With ]------------------------------------------ # # Note: Code part of javascript # ."<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\"><br>\n" # It shows the 'Original Code' Coding, but the 'Replaced With', it doesn't, since it has a # in it (but its not commented b/c it doesn't have a # at the first position) THANKS!!!!
neogia Posted April 11, 2006 Posted April 11, 2006 (edited) ... $line = FileReadLine($file,$linenumber) While (StringInStr($line, "#")) == 1 $linenumber=$linenumber+1 ... Instead of looking for a "#" anywhere in the line, I just changed it to look for a "#" in the first position, since that's the only place it would indicate a comment. Edited April 11, 2006 by neogia [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia
Valuater Posted April 11, 2006 Posted April 11, 2006 (edited) maybe While StringLeft($file, 1) <> "#" ;Or While StringLeft($file, 1) = "#" 8) LATE:.. but same idea Edited April 11, 2006 by Valuater
CrewXp Posted April 11, 2006 Author Posted April 11, 2006 haha!! Yall're awesome! One more thing, will this: If StringLen(StringStripWS($line, 3))>0 Work right and not do $mystring=$mystring&@LF&$line If the line read is a blank line like in my example file? Thx # ."<tr><td colspan=\"2\" bgcolor=\"#FFFFFF\"><br>\n" #
MHz Posted April 11, 2006 Posted April 11, 2006 This will skip the commented lines $handle_read = FileOpen('c:\yourfile.txt', 0) If $handle_read <> -1 Then $mystring="" While 1 $line = FileReadLine($handle_read) If @error Then ExitLoop If StringLeft(StringStripWS($line, 3), 1) = "#" Then ContinueLoop EndIf $mystring = $mystring & @CRLF & $line WEnd FileClose($handle_read) Msgbox(0, "My Current Code", $mystring) Else Msgbox(0, "Error", 'Unable to open file') EndIf If you want to skip an empty line, then I just do this If StringStripWS($line, 3) = "" Then ContinueLoop
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