Split strings whit strings

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

    Split strings whit strings

    Hi, I would like split string with more than one separator, and assign the
    result as array.

    For example:

    "car123house123 truck123"

    I need split my string in a array of 3 components

    car
    house
    truck

    How make that?

    I try the split function (<chain.split(" 123")>), but I get
    car
    23house
    23truck

    Thanks in advance for any help.

    Freddy Coal


  • Phill W.

    #2
    Re: Split strings whit strings

    Freddy Coal wrote:
    For example:
    "car123house123 truck123"
    I try the split function (<chain.split(" 123")>), but I get
    car
    23house
    23truck
    Imports VB=Microsoft.Vi sualBasic

    Dim s As String = VB.Split( chain, "123" )

    Watch out for that trailing delimiter - you'll probably wind up with a
    /four/-element array, with the last one being blank:

    s(0) = "car"
    s(1) = "house"
    s(2) = "truck"
    s(3) = (blank)

    HTH,
    Phill W.

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Split strings whit strings

      freddy

      Mostly is this problem the most simple to do by first changing the delimiter
      using replace and than split it.

      Cor

      "Freddy Coal" <freddycoal@gma il.withoutspan. comschreef in bericht
      news:ejhz5GOXHH A.3652@TK2MSFTN GP04.phx.gbl...
      Hi, I would like split string with more than one separator, and assign the
      result as array.
      >
      For example:
      >
      "car123house123 truck123"
      >
      I need split my string in a array of 3 components
      >
      car
      house
      truck
      >
      How make that?
      >
      I try the split function (<chain.split(" 123")>), but I get
      car
      23house
      23truck
      >
      Thanks in advance for any help.
      >
      Freddy Coal
      >

      Comment

      • Freddy Coal

        #4
        Re: Split strings whit strings

        Thanks a lot Phill, that is the perfect solution for me!

        Freddy Coal

        "Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
        news:es9j5v$j31 $1@south.jnrs.j a.net...
        Freddy Coal wrote:
        >
        >For example:
        >"car123house12 3truck123"
        >
        >I try the split function (<chain.split(" 123")>), but I get
        >car
        >23house
        >23truck
        >
        Imports VB=Microsoft.Vi sualBasic
        >
        Dim s As String = VB.Split( chain, "123" )
        >
        Watch out for that trailing delimiter - you'll probably wind up with a
        /four/-element array, with the last one being blank:
        >
        s(0) = "car"
        s(1) = "house"
        s(2) = "truck"
        s(3) = (blank)
        >
        HTH,
        Phill W.

        Comment

        Working...