Sign in to follow this  
Followers 0
UDX

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

3 posts in this topic

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;

first

second

fourth

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



#2 ·  Posted (edited)

Try this

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

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")
    EndIf
Next
FileClose($tmp_file)
FileCopy("c:\ttttmp.txt", "c:\ttt.txt", 1)
FileDelete("c:\ttttmp.txt")

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  
Followers 0