15,843,727 members
See more:
Hi All,

I have a string of numbers with some extra symbols like 123!2@2344#242%^. The symbols could be anywhere between the numbers. I should remove all those symbols.

I used
XML
```char[] MyChar = {'-', '_', '(', ')', '{', '}', '[', ']', '<', '>', '@', '#', '\$', '&', '*', '\'', ':', ';', ',' };
string strNumbers = Numbers.TrimEnd(MyChar);

but not working

Posted

## Solution 1

C#
```string input = "123!2@2344#242%^.";
string result = new string(input.Where(c => char.IsDigit(c)).ToArray());```

idhris2011 18-Nov-14 6:27am
Thanks Manas. That works
Manas Bhardwaj 18-Nov-14 6:29am
Glad it works. I would suggest that you accept this solution and vote appropriately, so that it can help other people as well.
Maciej Los 18-Nov-14 7:12am
5ed!
Linq rocks!
Manas Bhardwaj 18-Nov-14 7:18am
Thanks. Yes, it's very handy sometimes!

Takes sometime to get used to it though.
BillWoodruff 18-Nov-14 8:35am
+5

## Solution 2

"Not working" is not informative at all...

Test it:
C#
```char[] MyChar = {'^', '%', '!', '-', '_', '(', ')', '{', '}', '[', ']', '<', '>', '@', '#', '\$', '&', '*', '\'', ':', ';', ',' };
string strNumbers = @"123!2@2344#242%^";

string[] MyNumbers = strNumbers.Split(MyChar);
foreach(string num in MyNumbers)
{
Console.WriteLine(num);
}```

Result:
```123
2
2344
242```

Sergey Alexandrovich Kryukov 18-Nov-14 9:58am
5ed. I would only add: one cannot remove anything from a string, which is a read-only object. A string function can only create a brand-new string.
—SA
Maciej Los 18-Nov-14 13:07pm
Thank you, Sergey ;)