Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i know i can use string.replace to find a character and then replace it with another... what if i want to find 2 characters? what is the best thing to use? can this be done with one string.replace() or two of them (one for each character) or is there a better way?

 

i want to be able to remove '&' or '=' from a string.

 

thanks for the insight.

 


//Gets rid of '&' character
string test = "This & That";
test=test.Replace("&", " ");
Console.WriteLine(test);

  • Leaders
Posted

use System.Text.RegularExpressions.Regex

 

ie:

[Csharp]

string s = "test with = & the & sign = no good, we must remove the = & the & :)";

 

System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("([&])|([=])");

 

s = rgx.Replace(s," ");

 

Console.WriteLine(s);

 

[/csharp]

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