What is the fastest way (fastest to execute) to parse the following String into a list of Integers values? I need the values that are specified between the # # marks.
"#1#+#2#+#3#*1.23+#4#/2+#5#"
The above String should create a list of Integers:
- 1
- 2
- 3
- 4
- 5
Use
string.Split
to split your values into an array of strings, and then parse them withint.Parse
for integers ordouble.Parse
for floating-point values.If that is your input, you may have to also call
Trim
on your strings with the characters you want to remove, e.g.'*', '/', '+'
.May be this?
This checks whether
#
comes before and after a number, if yes matches it.Here is the ideone demo
The most readable solution would be something like
Maybe a faster implementation can be found - but if you do not have to parse several million numbers, I would prefer a readable solution.
Use regular expressions...
Fiddle: http://dotnetfiddle.net/GMqhXZ