Jump to content

replacing part of a line of text


Recommended Posts

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:

Link to comment
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.

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

  • Recently Browsing   0 members

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