Jump to content
Sign in to follow this  

Replace a string with a string and a string in next row?

Recommended Posts


Ok, coding and scripting is something I simply do not understand that easily so I do apologize for asking a possibly a stupid question.

Let's suppose I have some text in file;




What I want to do is simply insert "third" after second in the next row.

So trying to use replaceStringInFile I want my script to replace "second" with "second & CRLF third" but that's just not working. Should I use a different method if needed or is my syntax just way wrong (I mean i also tried $replace = "second" & @CRLF "third" but that wouldn't work also.

Is this just possible; to replace a string with two row strings?

I simply am using the sample file provided with AutoItv3 Help File.

Also from being previously on java forums is there a necessity to insert code in the tags and where can I find that button when posting a new message?

Share this post

Link to post
Share on other sites

Try this

$file = "one"&@crlf&"two"&"four"
$file = StringReplace($file,"two","two"&@CRLF&"three"&@crlf)

Welcome to the Forum :rolleyes:

Edited by Kogmedia

[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search

Share this post

Link to post
Share on other sites

Here is an example based somehow on how _ReplaceStringInFile works (using a temporary file)

#include <file.au3>

Dim $arr
_FileReadToArray("c:\ttt.txt", $arr)
$tmp_file = FileOpen("c:\ttttmp.txt", 2)
For $i=1 to UBound($arr)-1
    FileWriteLine($tmp_file, $arr[$i])
    If $arr[$i] = "two" Then
        FileWriteLine($tmp_file, "three")
FileCopy("c:\ttttmp.txt", "c:\ttt.txt", 1)

It doesn't look too good and I'm sure others can find more "elegant" ways to do it ... but This is what I can do :rolleyes:

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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