There is a string

string str = "0,5(1);1(1);0(2)"; 

I need to get the numbers that are перед скобками and drive them into the array. I do it like this:

 string str = "0,5(1);1(1);0(2)"; Regex rgx = new Regex(@"(\(\d\))"); var result = rgx.Replace(str, "").Split(';'); //"0,5(1);1(1);0(2)"->"0,5;1;0"->{"0,5","1","0"} 

1. If there is a more optimal way, please show, since at least 30 000 such lines will have to be processed at a time.

2. Now it is necessary to do the opposite - get the numbers в скобках in the array. How to implement it?

    1 answer 1

    Get simple:

     string str = "0,5(1);1(1);0(2)"; string[] numbers = str.Split(new[] { '(', ')', ';' }, StringSplitOptions.RemoveEmptyEntries); 

    In the numbers array, in places with even indices (0, 2, 4, ...) there will be numbers in front of the brackets, on odd ones, those in brackets:

     [0]: 0,5 [1]: 1 [2]: 1 [3]: 1 [4]: 0 [5]: 2