LerN

Replace string in txt file

5 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#5 ·  Posted (edited)

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