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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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
Answered 05/18/2011 by: murali.bhat
Purple Belt

Please log in to comment
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.
Answered 05/18/2011 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity