Jump to content

String Replace, replacing line


Recommended Posts

Hello.

I've got a problem with String Replace, I mean, I have for example that text:

blablabla

blablabla delete everything after this on this line blablabla2

blablabla

I don't know how to do that, that I get:

blablabla

blablabla

blablabla

Sorry for my bad english.

Link to comment
Share on other sites

I mean, I don't know which line I wanna change, it has to search the line where's 'delete everything after this line' and delete everything after this text.

$infile = "test.txt"

$data = FileRead ($infile)

$new_data3 = StringReplace ($data, @CRLF, '')

$hFile = FileOpen ($outfile, 2)

FileWrite ($hFile, $new_data3)

FileClose ($hFile)

and how to add in that, what i've said

Link to comment
Share on other sites

#include <string.au3>
#include <file.au3>

$i = 1
$j = _FileCountLines("test.txt")
do
    $line = FileReadLine("test.txt", $i)
    If NOT StringInStr($line, "some text to look for") Then
        FileWrite("output.txt", $line & @CRLF)
    Else
        ExitLoop
    EndIf
    $i += 1
Until $i = $j

#include <ByteMe.au3>

Link to comment
Share on other sites

$i = 1
$j = _FileCountLines("test.txt")
do
    $line = FileReadLine("test.txt", $i)
    If NOT StringInStr($line, "some text to look for") Then
        FileWrite("output.txt", $line & @CRLF)
    Else
        $lastline = StringSplit($line, "some text to look for", 1)
        FileWrite("output.txt", $lastline[1])
        Exit
    EndIf
    $i += 1
Until $i = $j

#include <ByteMe.au3>

Link to comment
Share on other sites

Here's a different way:

#include <file.au3>
#include <array.au3>
Local $aFile, $iline
_FileReadToArray("test.txt", $aFile)
$iline = _ArraySearch($aFile, "delete everything", 1, $aFile[0], 0, 1, 0)
_FileWriteFromArray("test.txt", $aFile, 1, $iline)

test.txt - before

Line 1
Line 2 delete everything after this on this line blablabla2
Line 3

test.txt - after

Line 1
Line 2 delete everything after this on this line blablabla2

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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