Replacing String - Case not sensitive
Hey,
My code replaces a specific word chosen by the user by another word, also chosen by user. Lets say the words are And & &, and each time there "And", it will be replaced with &.
The problem is that if the word is "and" (Lower Case), it wouldn't recognize it.
How can I overcome this problem? What about the Compare Method?
Code:
sWords = Split(sData, vbNewLine)
For i = LBound(sWords) To UBound(sWords) - 1
'Retrive text to be replaced
sText1 = Left(sWords(i), InStr(1, sWords(i), "=") - 1)
If InStr(1, sFilename, sText1) Then
'Replace sText1 with sText2
sText2 = Right(sWords(i), (Len(sWords(i)) - InStr(1, sWords(i), "=")))
sFilename = Replace(sFilename, sText1, sText2)
End If
Next i
ConvertWords = sFilename
Edit - totally forgot about LCase()...
Re: Replacing String - Case not sensitive
you can also use text compare
If InStr(1, sFilename, sText1, vbTextCompare)
you could also use replace function to do this
Re: Replacing String - Case not sensitive
Or you can convert the data that the user has entered, ie. "And", to lowercase at first using LCase(), and during the searching also, each word retieve from the data, convert that word also to lowercase. Then compare it. So that, no problem will occurs on replacing a particular word... :)