Split

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a string as follows:

string text = "Paris, New York , London,Lisbon,Oslo, Chicago ";

I need to get all words with no commas or spaces:
"Paris", "New", "York", "London", "Lisbon", "Oslo", "Chicago"

I am using (I think it is ok):
string[] words = text.Split(new char[] { ',' , ' '})

I need to get 3 words of the all I got. It can be the first 3 or any
other 3. It does no matter.

So words would have, for example: "Paris", "New", "York"

Is there a way to do this without using a loop?

Thanks,
Miguel
 
shapper said:
Hello,

I have a string as follows:

string text = "Paris, New York , London,Lisbon,Oslo, Chicago ";

I need to get all words with no commas or spaces:
"Paris", "New", "York", "London", "Lisbon", "Oslo", "Chicago"

I am using (I think it is ok):
string[] words = text.Split(new char[] { ',' , ' '})

I need to get 3 words of the all I got. It can be the first 3 or any
other 3. It does no matter.

So words would have, for example: "Paris", "New", "York"

Is there a way to do this without using a loop?

Thanks,
Miguel


text.Split to get the words then text.Trim() to remove the trailing and
leading spaces?

Eric B.
 
Back
Top