Jump to content

same-character reads?


Recommended Posts

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

Link to comment
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 :)

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...