String Replace

SIMIN

Regular
Joined
Mar 10, 2008
Messages
92
Hello,
I want to replace a string inside a special control.
For example replace any "a" word with "b".
You might think it's easy.
Something like:
Visual Basic:
SelectedElement.innerHTML = Replace(SelectedElement.innerHTML, FindText.Text, ReplaceText.Text)
But it has a problem!
It just replace all match case strings.
So if the string is in upper/lower/mixed mode, it cannot find it.
Now what should I do?
I was not able to find a way.
You may think something like:
Visual Basic:
SelectedElement.innerHTML = Replace(UCase(SelectedElement.innerHTML), UCase(FindText.Text), ReplaceText.Text)
But it will destroy my original text, since it will convert all the output to upper case!
I need help.
Thanks.
 
You may be able to use the .ToLower() method of String object... then use the IndexOf() method to find all locations of your "Find" String... then use Substring() method to replace starting at your IndexOf(), going "Find" String's Length and replace that with your "Replace" String.
 
You could try a regular expression - something like
C#:
string s = "Sample SAMPLE";
s = System.Text.RegularExpressions.Regex.Replace(s, "[aA]", "b");

I've not a clue if there is a better way though as regular expressions aren't my thing ;)
 
Back
Top