Problem with regular expression

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
 
L

Lars Wilhelmsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top