Removing wild characters from a string

  • Thread starter Thread starter SatishPasala
  • Start date Start date
S

SatishPasala

hi

I am tring to remove all the wild characters from a string. Is there
any short method to remove them in a single go.

I am right now tring to replace one by one.

Ex (999) 999-9999

I need 9999999999 with out all the charecters and spaces. I am trying
eliminate one by one now.

If you have any other ideas please post it

Thank You,
Satish
 
I don't know if this is the best solution, but you can loop through
character by character, examine each one, and if it is a digit, add it to a
brand new string. After you are done, the new string will have only the
digits.
 
Learn Regular Expressions. They can be used for updating strings as well as
searching...

You can accomplish in just a couple of lines of code (with Regular
Expressions) what would otherwise require many many lines of code in a
looping approach that builds a new string from the old OR uses
StringBuilder...

-HTH
 
From the server-side add on top of the codebehind:
using System.Text.RegularExpressions;

Then in the body of the function

//a pattern to find non word characters
Regex re = new Regex ("[^\\w]+");
//replace the matched pattern
Response.Write (re.Replace("(99)@3-87-9%!~(9175)", ""));
//should print 9938799175


If you are doing it using Javascript on the client-side:
alert("(99)@3-87-9%!~(9175)".replace(/[^\w]+/g,""));
 
The regular expression worked really good. thank Phillip

Thank you guys for the help.
satish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top