dr*****@nospam.nospam wrote:
Got this to work.
public string StripAplhanumeric(string sStrip)
{
string[] saStrip =
sStrip.Split(@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi jklmnopqrstuvwxyz!@#$%^&*(){}[]',<.>_-/?=+`~
".ToCharArray(),System.StringSplitOptions.None );
string rslt = string.Join("",saStrip);
return rslt;
}
Too lazy to test the timing. Seems to go pretty quick though.
Well, it'll be quick enough that you won't see any visible lag, but it
*is* pretty horribly inefficient (as well as still not stripping
accented characters etc). It may well not be an issue for you, but if
you're going to do millions of these, you might want to go with my
StringBuilder suggestion. I'm on a Mac at the minute so can't test it,
but the code would be something like:
// Note change of method name - "StripAlphaNumeric"
// doesn't describe what
// your method does accurately.
public string StripNonNumeric (string original)
{
StringBuilder builder = new StringBuilder();
foreach (char c in original)
{
if (char.IsDigit (c))
{
builder.Append (c);
}
}
return builder.ToString();
}
Jon