I have string of a particular type (A, B) C | D 0, 7 | E 0, 6 | F 0, 6 where A, B, C, D, E and F are known but the numbers has to be extracted.
Is there a way by which this can be done using Regex or something else in C#?
Assuming that's always the format of the string you'd be parsing, you could just use a simple String.Split:
var elements = yourString.Split(new[] {'(', ')', '|', ',', ' '},
StringSplitOptions.RemoveEmptyEntries);
Then just use elements[0]
to get the value represented by A
, etc. and cast it back to an integer or whatever you need to do with it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.