Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. split function

split function

Scheduled Pinned Locked Moved Visual Basic
questionhelp
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rupesh Kumar Swami
    wrote on last edited by
    #1

    hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1) now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?

    Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

    I T F 3 Replies Last reply
    0
    • R Rupesh Kumar Swami

      hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1) now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?

      Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

      I Offline
      I Offline
      iprasad007
      wrote on last edited by
      #2

      Change the separator if possible, otherwise first replace your separator string with a character separator and then perform spliting operation using ur new character separator. You can use Replace function to replace strings or characters in a string with other strings or characters.

      R 1 Reply Last reply
      0
      • I iprasad007

        Change the separator if possible, otherwise first replace your separator string with a character separator and then perform spliting operation using ur new character separator. You can use Replace function to replace strings or characters in a string with other strings or characters.

        R Offline
        R Offline
        Rupesh Kumar Swami
        wrote on last edited by
        #3

        hi iprasad2007, i already know this thing but i want to split my string on the basis of its substring not on any character. sorry,but this is not the answer of my question.

        Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

        1 Reply Last reply
        0
        • R Rupesh Kumar Swami

          hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1) now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?

          Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

          T Offline
          T Offline
          Tom Deketelaere
          wrote on last edited by
          #4

          The problem with this is that the split function expects a array of chars and when you give it a string it just uses the first char (in this case the "a"). I don't imidiatly know how you could solve this but I have a workaround:

          Dim path, str, seperat As String
          str = "0\0\0\0and--->Caption1"
          seperat = "and--->"
          Dim Title As String
          str = str.Replace(seperat, "~")
          Dim ItemInfo() As String = str.Split("~")
          path = ItemInfo(0)
          Title = ItemInfo(1)

          basicly the same code just that I replace the seperat string with "~" before splitting. This way ther is only 1 char to split on (or string of 1 char) and it works perfectly hope this helps

          K 1 Reply Last reply
          0
          • T Tom Deketelaere

            The problem with this is that the split function expects a array of chars and when you give it a string it just uses the first char (in this case the "a"). I don't imidiatly know how you could solve this but I have a workaround:

            Dim path, str, seperat As String
            str = "0\0\0\0and--->Caption1"
            seperat = "and--->"
            Dim Title As String
            str = str.Replace(seperat, "~")
            Dim ItemInfo() As String = str.Split("~")
            path = ItemInfo(0)
            Title = ItemInfo(1)

            basicly the same code just that I replace the seperat string with "~" before splitting. This way ther is only 1 char to split on (or string of 1 char) and it works perfectly hope this helps

            K Offline
            K Offline
            KeithF
            wrote on last edited by
            #5

            Im not sure if you want to use pure .Net code or not, but if you dont you can do this: Dim path, str, seperat As String str = "0\0\0\0and--->Caption1" seperat = "and--->" Dim Title As String Dim ItemInfo() As String = _**Split(str, seperat)**_ path = ItemInfo(0) Title = ItemInfo(1) The piece of code in bold italic is the VB6 way of doing it using strings and as you can see can it be used in VB .Net once the Microsoft.VisualBacic Namespace is included Hope this helps.

            R 1 Reply Last reply
            0
            • K KeithF

              Im not sure if you want to use pure .Net code or not, but if you dont you can do this: Dim path, str, seperat As String str = "0\0\0\0and--->Caption1" seperat = "and--->" Dim Title As String Dim ItemInfo() As String = _**Split(str, seperat)**_ path = ItemInfo(0) Title = ItemInfo(1) The piece of code in bold italic is the VB6 way of doing it using strings and as you can see can it be used in VB .Net once the Microsoft.VisualBacic Namespace is included Hope this helps.

              R Offline
              R Offline
              Rupesh Kumar Swami
              wrote on last edited by
              #6

              Thanks keith, its work

              Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

              1 Reply Last reply
              0
              • R Rupesh Kumar Swami

                hi everyone, i know this is very simple question. i want to split my string on the basis of seperator my code is following Dim path,str,seperat As String str="0\0\0\0and--->Caption1" seperat="and--->" Dim Title As String Dim ItemInfo() As String = str.split(seperat) path = ItemInfo(0) Title = ItemInfo(1) now i want to path contains "0\0\0\0". here i get correct result using above code but in title i want to store "Caption1"(on basis of seperator) but it stores "nd--->Caption1". can anybody told where i m wrong? how can i solve this problem?

                Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

                F Offline
                F Offline
                Fahad Sadah
                wrote on last edited by
                #7

                I believe the function you are looking for is a tokenize function (split a string by a delimiter(separator)) EDIT: I tried to write one here for you but got confused, I will tommorow when I got more time. EDIT AGAIN: Mine doesn't fit in memory. -- modified at 3:12 Saturday 1st September, 2007

                All of my programs are downloadable at fahadsadah.co.nr

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups