Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Administrators
Posted

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 ;)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...