Why don't you want to use regular expressions? Regular expressions are heavily optimised and will be much faster than any hand written hack.
This is java (as I run linux and can't run c# as a result), but I hope you get the idea.
input.replace("view(","").replace("'","").replace("\"","").replace(");","");
A million repetitions of the above runs in about 6 seconds on my computer. Whereas, the regular expression below runs in about 2 seconds.
// create java's regex matcher object // matcher is looking for sequences of digits (valid integers) Matcher matcher = Pattern.compile("(\\d+)").matcher(s); StringBuilder builder = new StringBuilder(); // whilst we can find matches append the match plus a comma to a string builder while (matcher.find()) { builder.append(matcher.group()).append(','); } // return the built string less the last trailing comma return builder.substring(0, builder.length()-1);
If you want to find valid decimals as well as integers then use the following pattern instead. Though it runs slightly slower than the original.
"(\\d+(\\.\\d*)?)"
bestas inbest performance, right?