Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted

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

Posted

Hmm sleepydvdr idk, but it deletes full line, for example :

blablabla bla

bla bla bla some text to look for bla bla

bla bla bla

And the output:

blablabla bla

;/ Is that possible to do ?

Posted

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

Posted

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.

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
  • Recently Browsing   0 members

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