legend

Replace text after a string

6 posts in this topic

Hello,

How would I replace something after a string?

Example:

SourceFiles0=C:\Users\flox\Desktop\build\

So I want to replace everything in this line that comes after: SourceFiles0=

Share this post


Link to post
Share on other sites



I suppose that you know SourceFiles0= so. Why not add new string to that.

 

Saludos

Share this post


Link to post
Share on other sites
$var="SourceFiles0=C:\Users\flox\Desktop\build\"
$iCnt = StringLen("SourceFiles0=")
ConsoleWrite("$iCnt =  " & $iCnt & @CRLF)
$varCut = StringLeft($var, $iCnt)
ConsoleWrite("$varCut =  " & $varCut & @CRLF)
$newString =  $varCut & " Something Else"
ConsoleWrite("$newString =  " & $newString & @CRLF)

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I need to replace a string in a file.

so I need to replace: 

SourceFiles0=C:\Users\flox\Desktop\build\

with just: 

SourceFiles0=

 

(I don't know at what line number SourceFiles0=C:\Users\flox\Desktop\build\) are

Edited by legend

Share this post


Link to post
Share on other sites

something like:

Local $aFile=FileReadToArray("file.txt")


For $i=0 to UBound($aFile)-1
   If StringInStr($aFile[$i],"SourceFiles0=") Then
      $aFile[$i]="SourceFiles0=" & "Replacestringhere"
   EndIf
   FileWrite("newfile.txt",$aFile[$i] & @CRLF)
Next

Saludos

Share this post


Link to post
Share on other sites

Thank's the was just what i needed :)

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