Wednesday 15 January 2014

Split a complex string using RegEx in c# -


I have to split the string into an array, split it at \ r \ n. I want to use Reggae but the following is included in the beginning of the string or any \ r \ n:

  RegEx.Split (stringIn, @ "\ r \ n ")   

The string I see looks like:

 " \ r \ n4: \ r \ n: 20 : 00412 \ r \ n: 21: 123456 / DEV \ r \ n: 13C: / A234567Z / 1359 + 0100 \ r \ n: 32A: \ r \ n "  

It should be output as an array:

  4: 20: 00412: 21: 123456 / God : 32A:   

etc

you trim You can do this by using the trim method:

  var trimmed = stringIn.Trim new [] {'\ n', '\ r'}) ;   

The results of split will no longer contain unwanted characters:

  var token = regx. Split (Trimmed, @ "\ r \ n")    

No comments:

Post a Comment