Q: Tricky Split Question  
Author Message
sje2555





PostPosted: Tue Apr 17 12:09:26 CDT 2007 Top

Visual C#.Net >> Q: Tricky Split Question

Hi!

I have a string containing this information:

Including file: Myfile.fle (C:\Program
Files\Application\Source\Myfile.fle)
After myfile.fle there are three spaces!

Since i use the folowing:

string[] splitted = unsplittedString.split(new char[]{' '})

The splitted string is outputed like this ofcourse:
Including
file:
Myfile.fle


(C:\Program
Files\Application\Source\Myfile.fle)

which is correct. BUT, now for the tricky part.

I only want to split if there is only ONE space and i dont want to split
anything between the ( and )

so basicly i want this output:
Including
file:
Myfile.fle
(C:\Program Files\Application\Source\Myfile.fle)

Any ideas you geniouses out there :)

/Martin

DotNet288  
 
 
sonicwrx





PostPosted: Tue Apr 17 12:09:26 CDT 2007 Top

Visual C#.Net >> Q: Tricky Split Question On Apr 17, 11:47 am, "Martin Arvidsson, Visual Systems AB"

> Hi!
>
> I have a string containing this information:
>
> Including file: Myfile.fle (C:\Program
> Files\Application\Source\Myfile.fle)
> After myfile.fle there are three spaces!
>
> Since i use the folowing:
>
> string[] splitted = unsplittedString.split(new char[]{' '})
>
> The splitted string is outputed like this ofcourse:
> Including
> file:
> Myfile.fle
>
> (C:\Program
> Files\Application\Source\Myfile.fle)
>
> which is correct. BUT, now for the tricky part.
>
> I only want to split if there is only ONE space and i dont want to split
> anything between the ( and )
>
> so basicly i want this output:
> Including
> file:
> Myfile.fle
> (C:\Program Files\Application\Source\Myfile.fle)
>
> Any ideas you geniouses out there :)
>
> /Martin

If I understand you correctly changing the line to

string[] splitted = unsplittedString.split(new char[]{' '},
StringSplitOptions.RemoveEmptyEntries)
I am assuming that the two spaces before (C:\Program files...) aren't
necessary.

Hope this helps.

 
 
Ignacio





PostPosted: Tue Apr 17 13:07:56 CDT 2007 Top

Visual C#.Net >> Q: Tricky Split Question Hi,

I do not quite understand what you want.

What are you trying to do by spliting it in spaces?



> Hi!
>
> I have a string containing this information:
>
> Including file: Myfile.fle (C:\Program
> Files\Application\Source\Myfile.fle)
> After myfile.fle there are three spaces!
>
> Since i use the folowing:
>
> string[] splitted = unsplittedString.split(new char[]{' '})
>
> The splitted string is outputed like this ofcourse:
> Including
> file:
> Myfile.fle
>
>
> (C:\Program
> Files\Application\Source\Myfile.fle)
>
> which is correct. BUT, now for the tricky part.
>
> I only want to split if there is only ONE space and i dont want to split
> anything between the ( and )
>
> so basicly i want this output:
> Including
> file:
> Myfile.fle
> (C:\Program Files\Application\Source\Myfile.fle)
>
> Any ideas you geniouses out there :)
>
> /Martin
>