什么是去除串的最佳方法是什么? [英] What's the best way to remove strings?
本文介绍了什么是去除串的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要思想与最佳的性能,除去/过滤字符串
I need ideas with the best performance to remove/filter strings
我有:
string Input = "view('512', 3, 159);";
什么是最好的表现方法,以消除视图(和);和引号? 我可以这样做:
What's the best performance way to remove "view(" and ");" and the quotes? I can do this:
Input = Input.Replace("view(","").Replace("'","").Replace("\"","").Replace(");","");
但似乎相当不雅。
but it seems rather inelegant.
Input.Split('(')[1].Split(')')[0].Replace("'", "");
它似乎相当好
it seems rather better
我想没有用常规的前pression做到这一点;我需要做出更快的应用程序有什么我可以。 提前致谢! :)
I want no do it by using regular expression; I need make the faster application what I can. Thanks in advance! :)
推荐答案
您可以使用一个简单的LINQ语句:
You could use a simple linq statement:
string Input = "view('512', 3, 159);";
string output = new String( Input.Where( c => Char.IsDigit( c ) || c == ',' ).ToArray() );
输出:512,3,159
Output: 512,3,159
如果你想要的空间,只需添加一个检查where子句。
If you want the spaces, just add a check in the where clause.
这篇关于什么是去除串的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文