Problem with regular expression

  • Thread starter Thread starter Daniel Suarez
  • Start date Start date
D

Daniel Suarez

Hi there,

I got the following expression in C#:
string expresion = " 00.00% 00.00% 23.00%
";

I want to split it out, with the following code:

Regex regex = new Regex(@"\s+");
expresion = " 00.00% 00.00% 23.00% ";
partes = regex.Split(expresion);

And I get the following:

partes[0]=""
partes[1]="00.00%"
partes[2]="00.00%"
partes[3]="23.00%"
partes[4]=""

I don't want to get partes[0] and partes[4] empty strings...What is wrong in
my regular expression?

Thanks in advance
 
Hi Daniel,

I don't want to get partes[0] and partes[4] empty strings...What is wrong in
my regular expression?

The easiest thing do do is to .Trim() the expression string before you split
it.

Regards,

Lars Wilhelmsen
Software Engineer
Teleplan A/S, Norway
 
Back
Top