Jump to content

Delete specify character in a line in INI file


shay
 Share

Recommended Posts

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

Link to comment
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)

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
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

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...