I need ideas with the best performance to remove/filter strings
I have:
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
I want no do it by using regular expression; I need make the faster application what I can. Thanks in advance! :)
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() );
Output: 512,3,159
If you want the spaces, just add a check in the where clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With