从字符串中删除字符 [英] Remove characters from string

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

问题描述

大家好,



我有一串带有一些额外符号的数字,比如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 strNumbers = Numbers.TrimEnd(MyChar);

但不工作

提前致谢
', '&', '*', '\'', ':', ';', ',' }; string strNumbers = Numbers.TrimEnd(MyChar); but not working Thanks in advance


这个怎么样?



What about this?

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


不工作根本没有提供信息......



测试它:

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

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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆