SIMIN Posted July 17, 2008 Posted July 17, 2008 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: 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: 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. Quote
Nate Bross Posted July 17, 2008 Posted July 17, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted July 18, 2008 Administrators Posted July 18, 2008 You could try a regular expression - something like 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 ;) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darkforcesjedi Posted July 18, 2008 Posted July 18, 2008 Regex has an IgnoreCase option ;) .Replace(myString, "rEpLacE ME", "with me", RegexOptions.IgnoreCase) Quote
Administrators PlausiblyDamp Posted July 18, 2008 Administrators Posted July 18, 2008 Told you I was no good with regex ;) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.