Difficulty with Regex

0

I have the following content in a string :

  

| 1300 | 11349 | 03042016 | 10857,000 | 000 | 10857,000 | 444,470 | 10412,530 | 25,530 | 0,000 | 10387,000 |   | 1310 | 8 | 4657,000 | 000 | 4657,000 | 444,470 | 4212,530 | 53030 | 0.000 | 4207,000 |   | 1320 | 25 |||||| 281647,640 | 281203,170 | 0,000 | 444,470 |   | 1320 | 26 |||||| 308202,420 | 308202,420 | 0.000 | 0.000 |   | 1310 | 11 | 6200,000 | 0.000 | 6200,000 | 0.000 | 6200,000 | 20,000 | 000 | 6180,000 |   | 1320 | 28 |||||| 439837,300 | 439837,300 | 0.000 | 0.000 |   | 1300 | 11518 | 03042016 | 8057,000 | 0.000 | 8057,000 | 560,519 | 7496,481 | 0.000 | 25,519 | 7522,000 |   | 1310 | 7 | 8057,000 | 000 | 8057,000 | 560,519 | 7496,481 | 0.000 | 25,519 | 7522,000 |   | 1320 | 13 |||||| 420207,150 | 420146,581 | 0,000 | 60,569 |   | 1320 | 14 |||||| 457108,130 | 456806,946 | 0,000 | 301,184 |   | 1320 | 21 |||||| 460614,020 | 460518,267 | 0,000 | 95,753 |   | 1320 | 22 |||||| 544902,750 | 544799,677 | 0,000 | 103,073 |

I would like to break this string in a array for blocks that begin with | 1300 |

I would have a two-position vector , thus each position of the vector for example:

Position 1:

  

| 1300 | 11349 | 03042016 | 10857,000 | 000 | 10857,000 | 444,470 | 10412,530 | 25,530 | 0,000 | 10387,000 |   | 1310 | 8 | 4657,000 | 000 | 4657,000 | 444,470 | 4212,530 | 53030 | 0.000 | 4207,000 |   | 1320 | 25 |||||| 281647,640 | 281203,170 | 0,000 | 444,470 |   | 1320 | 26 |||||| 308202,420 | 308202,420 | 0.000 | 0.000 |   | 1310 | 11 | 6200,000 | 0.000 | 6200,000 | 0.000 | 6200,000 | 20,000 | 000 | 6180,000 |   | 1320 | 28 |||||| 439837,300 | 439837,300 | 0.000 | 0.000 |

Position 2

  

| 1300 | 11518 | 03042016 | 8057,000 | 0.000 | 8057,000 | 560,519 | 7496,481 | 0.000 | 25,519 | 7522,000 |   | 1310 | 7 | 8057,000 | 000 | 8057,000 | 560,519 | 7496,481 | 0.000 | 25,519 | 7522,000 |   | 1320 | 13 |||||| 420207,150 | 420146,581 | 0,000 | 60,569 |   | 1320 | 14 |||||| 457108,130 | 456806,946 | 0,000 | 301,184 |   | 1320 | 21 |||||| 460614,020 | 460518,267 | 0,000 | 95,753 |   | 1320 | 22 |||||| 544902,750 | 544799,677 | 0,000 | 103,073 |

I tried the code below, but it did not work

string[] arr1300 = Regex.Split(conteudo, @"(\|1300\|)");
    
asked by anonymous 30.05.2016 / 23:03

1 answer

3

I think a Split normal solves your problem:

string stringSplit = "|1300|";
string[] arr1300 = conteudo.Split(new string[] { stringSplit }, StringSplitOptions.RemoveEmptyEntries);

After Split simply concatenate the " |1300| " so that the positions are the same you want:

string posicao1 = stringSplit + arr1300[0];
string posicao2 = stringSplit + arr1300[1];

If you have more than two positions you can concatenate " |1300| " in all positions at once:

arr1300 = arr1300.Select(x => stringSplit + x).ToArray();
    
30.05.2016 / 23:45