Sign in to follow this  
Followers 0
shay

Delete specify character in a line in INI file

15 posts in this topic

Hi

i wont to remove specify character from 2 lines in INI file,

i try StringReplace but i don't think that this is the right command to use.

the line look like that:

;this is test line = 1

;this is second line = 1

this is third line = 1

need to look like that (remove the ";")

this is test line = 1

this is second line = 1


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites



StringReplace should work. How did you use it? Give us the script you wrote so we can help more.

Hi,

have a look at _ReplaceStringInFile.

;-))

Stefan

Share this post


Link to post
Share on other sites

They're essentially the same and the poster said they'd used it but they didn't think it was the right function. It would work if done properly but _ReplaceStringInFile probably would be easier for the poster (or harder depending :D)

Share this post


Link to post
Share on other sites

i try that but obviously i`m way off! :D

$path2 = "root to file\test.ini"
$line = IniReadSection ( $path2, "general")
StringReplace( ";", "{DELETE}",2)

"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

Dunno why string replace shouldn't work..

$line=";this is line 1"
MsgBox(4096,"",StringReplace($line,";",""))

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Just in case you can't draw what you need from Manjish's example (don't know why you wouldn't be able to but some people can't) you have

StringReplace( ";", "{DELETE}",2)

when you need StringReplace($line1,";","") . I had a feeling your implementation was wrong so that's why I asked. Hope the info you got here helps. Edited by dbzfanatic

Share this post


Link to post
Share on other sites

Ok now i think i know what is wrong

i need to read a INI section using "IniReadSection"

then apply "StringReplace($line1,";","",2)"

then write to the INI file

but if i`ll write to file i will have duplicate Sections, no? :D


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

You won't have duplicates if you overwrite only the line you want. For your needs it would probably be easier to use _ReplaceStringInFile() as stated above.

Share this post


Link to post
Share on other sites

ok i`m able to do this

$s = FileOpen("c:\test.ini",0 )
$file = FileRead ($s,100)
MsgBox(0, "test",StringReplace($file,";","",2))

i unable to do that with"IniReadSection" command,

i prefer doing this with "IniReadSection"

so the code will be more resistant to any changes in the INI file.

any idea?


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

ok i`m able to do this

$s = FileOpen("c:\test.ini",0 )
$file = FileRead ($s,100)
MsgBox(0, "test",StringReplace($file,";","",2))

i unable to do that with"IniReadSection" command,

i prefer doing this with "IniReadSection"

so the code will be more resistant to any changes in the INI file.

any idea?

Hi,

#include <File.au3>
_ReplaceStringInFile ("c:\test.ini",";","") ; all ; are replaced by empty string

;-))

Stefan

Share this post


Link to post
Share on other sites

thanks

i use the _ReplaceStringInFile.

i change the #File.au3 so it will run only on the first string,

i Thoth that i can use the IniReadSection,

that way if the INI file will be changed my script wont be effacted


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

Hi,

IniReadSection doesn't read lines with a ; at the beginning.

So function will only read line 3 in.

;-((

Stefan

Share this post


Link to post
Share on other sites

When you read the ini into your program, all lines with comments are ignored because they're not useful for your program. If you want to replace ; characters in a file, then you should use the examples posted above. Forget about IniRead...

Share this post


Link to post
Share on other sites

OK thx you all!!!

love this forum! :D


"If the facts don't fit the theory, change the facts." Albert Einstein

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