Jump to content
LerN

Replace string in txt file

Recommended Posts

LerN

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.
 

Share this post


Link to post
Share on other sites
genius257

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.

  • Like 1

Share this post


Link to post
Share on other sites
LerN

i need something to replace in the section it self not searching in all the file for "Active" and that's the problem

Share this post


Link to post
Share on other sites
Jos

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

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
LerN
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

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.