Jump to content

Delete row in a text file


 Share

Recommended Posts

hello to all,

need help.

need to replace a row in my text file :

a
b
c
d
e
f
i
g
h
l
z
z
z
z
z

you see a lot of identical row 'z'

if use _ReplaceStringInFile function replace all 'z'

I know row number in file, is possible to replace that line and no others ?

Thank you for help !

m.

Link to comment
Share on other sites

hello to all,

need help.

need to replace a row in my text file :

a
b
c
d
e
f
i
g
h
l
z
z
z
z
z

you see a lot of identical row 'z'

if use _ReplaceStringInFile function replace all 'z'

I know row number in file, is possible to replace that line and no others ?

Thank you for help !

m.

Try this:

#Include <File.au3>

Func ReplaceInRow($FILE,$ROW,$SEARCH,$REPLACE)
$OPEN = FileOpen($FILE,0)
$LINE = FileReadLine($OPEN,$ROW)
FileClose($OPEN)
$NEW_LINE = StringReplace($LINE,$SSTRING,$RSTRING)
_FileWriteToLine($FILE,$ROW,$NEW_LINE,1)
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

hmmm some problems,

#Include <File.au3>

dim $FILE,$ROW,$SEARCH,$REPLACE,$SSTRING,$RSTRING

$FILE = "list.txt"

ReplaceInRow($FILE,5,"e","find_find_find_find")


Func ReplaceInRow($FILE,$ROW,$SEARCH,$REPLACE)
    $OPEN = FileOpen($FILE,0)
    $LINE = FileReadLine($OPEN,$ROW)
    FileClose($OPEN)
    $NEW_LINE = StringReplace($LINE,$SSTRING,$RSTRING)
    _FileWriteToLine($FILE,$ROW,$NEW_LINE,1)
EndFunc

understand concept but can't able to use...

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