Sign in to follow this  
Followers 0
CrewXp

Stringinstr Help. Thanks!

5 posts in this topic

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!!!!

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

maybe

While StringLeft($file, 1) <> "#" 
    
;Or
    
While StringLeft($file, 1) = "#"

8)

LATE:.. but same idea

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

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"

#

Share this post


Link to post
Share on other sites

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

:think:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0