Split

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    #1

    Split

    Hello,

    I have a string as follows:

    string text = "Paris, New York , London,Lisbon,O slo, 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
  • Peter Duniho

    #2
    Re: Split

    On Thu, 09 Oct 2008 15:37:49 -0700, shapper <mdmoura@gmail. comwrote:
    [...]
    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.
    This is essentially the same question you asked in a different thread.
    Please don't start new threads for the same question.

    Pete

    Comment

    • Eric B.

      #3
      Re: Split

      "shapper" <mdmoura@gmail. comwrote in message
      news:d7897dfa-4fa2-4afb-af96-36c85650c34b@l6 4g2000hse.googl egroups.com...
      Hello,
      >
      I have a string as follows:
      >
      string text = "Paris, New York , London,Lisbon,O slo, 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.

      Comment

      • gerry

        #4
        Re: Split

        Array.Copy()


        "shapper" <mdmoura@gmail. comwrote in message
        news:d7897dfa-4fa2-4afb-af96-36c85650c34b@l6 4g2000hse.googl egroups.com...
        Hello,
        >
        I have a string as follows:
        >
        string text = "Paris, New York , London,Lisbon,O slo, 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

        Comment

        Working...