Jump to content

Replace string in txt file


LerN
 Share

Recommended Posts

Hi,
iam trying to replace string in file contains strings like this :
 

[name1]
Case = Active
[name2]
Case = Active
[name3]
Case = Done
[Name4]
Case = Done

If i used:

$readCaseFile = IniRead("Names.txt","name2","Case","")
_ReplaceStringInFile("Names.txt",$readCaseFile,"Replaced",0,0)

it will replace the first Active that in section name1 while i wanted it to replace in the section name2
so have u any idea ?
if u don't understand tell me and i can explain more, thanks.
 

Link to comment
Share on other sites

Hi @LerN.

Doesn't IniWrite fulfill your problem?

$readCaseFile = IniRead("Names.txt","name2","Case","")
IniWrite("Names.txt", "name2", "Case", "Replaced")

If not, _ReplaceStringInFile is troublesome, if you do not first find the precise point of the match, in case of multiple matches.

Link to comment
Share on other sites

  • Developers

That is what the code does posted by @genius257, just replace the value for case in section [name2].

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Just now, Jos said:

That is what the code does posted by @genius257, just replace the value for case in section [name2].

Jos

My internet isn't good , i didn't see his comment until now and the problem fixed 
i wrote my comment before him but bec, the internet posted after he replayed thanks both :)

Edited by LerN
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...