本文介绍了从字符串中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一串带有一些额外符号的数字,比如123!2 @ 2344#242%^。符号可以是数字之间的任何位置。我应该删除所有这些符号。



我使用

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

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

but not working

Thanks in advance

推荐答案


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


char[] MyChar = {'^', '%', '!', '-', '_', '(', ')', '{', '}', '[', ']', '<', '>', '@', '#', '


这篇关于从字符串中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:25