/build/static/layout/Breadcrumb_cap_w.png

Remove Entry in INI File

Hi There,

I am not good with scripting and is struggling with an INI file. I want to check and remove a certain characters on string.
-------------------------------------
[MyINI]

YourINI=One,Two,Three,Four
-------------------------------------

I want to remove the "One" no matter what its position is and if it is the only entry, it will be blank:
-------------------------------------
[MyINI]

YourINI=
-------------------------------------

It could also be like this:
-------------------------------------
[MyINI]

YourINI=Two,Three,One,Four
-------------------------------------

I found the thread for VBCab which tackles it but still could not make my scripts work. Thank you!

0 Comments   [ + ] Show comments

Answers (2)

Posted by: murali.bhat 12 years ago
Purple Belt
0
Try this:


Option Explicit

Dim oFSO, sFile, oFile, sText, sNewText

Set oFSO = CreateObject("Scripting.FileSystemObject")

sFile = "<File Path>"

'On error resume next
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do Until oFile.AtEndOfStream
sText = oFile.ReadLine
If Instr(1, Trim(sText), "YourINI") <> 0 Then
If Instr(1, Trim(sText), ",One,") <> 0 Then
sNewText = sNewText & vbcrlf & Replace(sText, ",One,",",")
elseif Instr(1, Trim(sText), "One,") <> 0 Then
sNewText = sNewText & vbcrlf & Replace(sText, "One,","")
elseif Instr(1, Trim(sText), "One") <> 0 Then
sNewText = sNewText & vbcrlf & Replace(sText, "One","")
end if
Else
sNewText = sNewText & vbcrlf & sText
End If
Loop

oFile.Close

Set oFile = oFSO.OpenTextFile(sFile, 2)
oFile.Write sNewText

End If

Set oFSO = Nothing
Posted by: anonymous_9363 12 years ago
Red Belt
0
I can't see what the difficulty is in using the INI class but...whatever...

As to the posted script (and for any script using the class, if you return to that), it'd be simpler to use Split using the 'equals' sign as the separator, then Split again using comma as the separator, then testing for the string. You can then reassemble the string using the array elements.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ