Sign in to follow this  
Followers 0
Burgs

same-character reads?

3 posts in this topic

Greetings,

I'm using the following code to attempt to read a file that contains two values followed by a "%" sign. I wish to read each value preceding the "%" sign, and then write the values to another file. The problem is that it seems that the second value is overwriting the first when the file is written with the values...I cannot figure how to work-around this?

While 1

$percent = FileReadLine($interest2)

If @error = -1 Then ExitLoop

;compare line to search for "%"...

$key = StringInStr($percent, " %")

if $key > 0 Then

$GOLD = StringRight($percent, 7)

EndIf

;compare line to search for "second %"...

$key2 = StringInStr($percent, " %")

if $key2 > 0 Then

$GOLD2 = StringRight($percent, 7)

EndIf

Wend

Share this post


Link to post
Share on other sites



There is a faster way than reading one line at a time.

Read the whole file in one string, then use StringSplit for "%".

$fil = FileOpen("c:\test.txt", 0)
$str = FileRead($fil)   ;read the file
FileClose($fil)

$res = FileOpen("c:\result.txt", 2)

$result = StringSplit($str, "%")
For $i=2 To UBound($result)-1
    FileWriteLine($res, StringLeft($result[$i], 7))
Next

FileClose($res)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Thank you for your post, that information was very useful...

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