Sign in to follow this  
Followers 0
vickerps

replacing part of a line of text

6 posts in this topic

I want to replace part of a line of text

For example

this is line 1

this is line 2

this is line 3

this is line 23 the number is NO

this is line 24 the number is NO

this is line 25

this is line 33 the number is NO

The number you require is NO

That annoying number you want is NO

Please phone NO for assistance

How do i replace 'NO' with say '12345678' throughout the text file

hope this make sense :ph34r:

Share this post


Link to post
Share on other sites



Scan the entire file line by line, set variable to the line contents

$text = StringReplace("<line contents>", "NO", "123456789")

Write string back to the line you read out of.


Sitting comfortably behind the code.

Share this post


Link to post
Share on other sites

how do write the string back to the text file

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You might want to check the help file for anything that contains "file" or "write" in its name or ask about the specific problems you have.

Edited by sugi

Share this post


Link to post
Share on other sites

I believe what sugi meant to say was:

FileWriteLine(<filename>, <line>)


Sitting comfortably behind the code.

Share this post


Link to post
Share on other sites

thanks i figured it out after i spent the time to look at it properly

_FileReadToArray( "c:\list.txt", $temp )    

For $n = 1 to $temp[0]

    $temp[$n]=  StringReplace($temp[$n],$MidToChange, Guiread($MID))
     FileWrite("tempfilename.txt",$temp[$n])
    
    IF $n < $temp[0] THEN FileWrite("tempfilename.txt",@lf)

Next

FileCopy("tempfilename.txt","c:\list.txt",1)
FileDelete("tempfilename.txt")

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