0

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#?

2

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is one option even I thought of. I was thinking if its possible with regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.