Can any one please suggest me how to remove numerics in a string of c#
Removing numerics(like 2,4,5...) from a string in c#
Collapse
X
-
Tags: None
-
scan through each character of the string.
if the charachetr is not a numeric copy it to the end of a new string.
Once the above cycle is completed, reference the original string to the new string, and you have your result
cheers -
Hi,
Try this code below... first drag and drop a button control in your webform. then copy paste this code below:
ok enjoy!!
private void Button1_Click(o bject sender, System.EventArg s e)
{
string txtInput = "ABCX123 DEFG111HIGK912" ;
string txt;
txt = "";
string c;
int P;
string o = "1234567890 ";
for (int i = 0; i < txtInput.Length ; i++)
{
c = txtInput.Substr ing(i,1);
P = o.IndexOf(c);
if (P < 0)
{
txt += c;
}
}
Response.Write( txt);
}
regards,
ruel sucgang
Originally posted by naveenkenexaCan any one please suggest me how to remove numerics in a string of c#Comment
-
hi friends at last i found that its easy using regular expressions
steps to reproduce:
1. use 'using system.text.reg ularexpression' namespace
2. modifiedstring = Regex.Replace(p reviousstring, "[^0-9]+", "");
Cheers
NaveenComment
Comment