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. Reading to an array

Reading to an array

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structureshelpquestion
6 Posts 3 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.
  • C Offline
    C Offline
    charchabil03
    wrote on last edited by
    #1

    Hey Guys Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow: Dim s As String, h As String Dim delim(1) As Char delim(0) = "/" delim(1) = " " Dim f() As String s = A1/EXT ""BK82 LB73 21233"" 105 061018 1804 f = s.Split(delim) ----------- The problem that I m facing is as follow : even what is inside the double quotes is devided into parts what should i add to my code (or any other solution), in order to keep what is inside the "" with splitting Regards, Ramy

    C R 2 Replies Last reply
    0
    • C charchabil03

      Hey Guys Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow: Dim s As String, h As String Dim delim(1) As Char delim(0) = "/" delim(1) = " " Dim f() As String s = A1/EXT ""BK82 LB73 21233"" 105 061018 1804 f = s.Split(delim) ----------- The problem that I m facing is as follow : even what is inside the double quotes is devided into parts what should i add to my code (or any other solution), in order to keep what is inside the "" with splitting Regards, Ramy

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You need to use a regex to follow more complex rules such as 'split on spaces not within quotes'.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • C charchabil03

        Hey Guys Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow: Dim s As String, h As String Dim delim(1) As Char delim(0) = "/" delim(1) = " " Dim f() As String s = A1/EXT ""BK82 LB73 21233"" 105 061018 1804 f = s.Split(delim) ----------- The problem that I m facing is as follow : even what is inside the double quotes is devided into parts what should i add to my code (or any other solution), in order to keep what is inside the "" with splitting Regards, Ramy

        R Offline
        R Offline
        Reuven Elliassi
        wrote on last edited by
        #3

        Try this: dim S2Split As string = "A1/EXT "BK82 LB73 21233" 105 061018 1804" dim delim(1) as char delim(0)="/" delim(1)=" " dim f(0) as string dim I as integer dim J as short dim Tmp as string="" dim Ad as boolean dim fPos as integer =0 for i=0 to s2split.length-1 Ad=true for j=0 to 1 if s2split(i)=delim(j) then ad=false end for if ad=true then tmp=tmp & s2split(i) else f(fpos)=tmp tmp="" fpos += 1 'New feature in VB.NET 2005 ;) redim preserve f(fpos) 'preserve means that increasing f and saving the ' 'previous data end if end for

        C 1 Reply Last reply
        0
        • R Reuven Elliassi

          Try this: dim S2Split As string = "A1/EXT "BK82 LB73 21233" 105 061018 1804" dim delim(1) as char delim(0)="/" delim(1)=" " dim f(0) as string dim I as integer dim J as short dim Tmp as string="" dim Ad as boolean dim fPos as integer =0 for i=0 to s2split.length-1 Ad=true for j=0 to 1 if s2split(i)=delim(j) then ad=false end for if ad=true then tmp=tmp & s2split(i) else f(fpos)=tmp tmp="" fpos += 1 'New feature in VB.NET 2005 ;) redim preserve f(fpos) 'preserve means that increasing f and saving the ' 'previous data end if end for

          C Offline
          C Offline
          charchabil03
          wrote on last edited by
          #4

          Dear Reuven. thx for your help Just a Question? Have you tried out this code? coz when i was trying out ,i faced a problem with the foor loop-(Next) that's why i couldnt compile this code

          Regards Ramy

          R 1 Reply Last reply
          0
          • C charchabil03

            Dear Reuven. thx for your help Just a Question? Have you tried out this code? coz when i was trying out ,i faced a problem with the foor loop-(Next) that's why i couldnt compile this code

            Regards Ramy

            R Offline
            R Offline
            Reuven Elliassi
            wrote on last edited by
            #5

            My mistake, I replaced Next I and Next J with end for... for i=0 to s2split.length-1 Ad=true for j=0 to 1 if s2split(i)=delim(j) then ad=false

            end for

            'replace with Next J if ad=true then tmp=tmp & s2split(i) else f(fpos)=tmp tmp="" fpos += 1 'New feature in VB.NET 2005 redim preserve f(fpos) 'preserve means that increasing f and saving the ' 'previous data end if

            end for

            'replace with Next I Reuven

            C 1 Reply Last reply
            0
            • R Reuven Elliassi

              My mistake, I replaced Next I and Next J with end for... for i=0 to s2split.length-1 Ad=true for j=0 to 1 if s2split(i)=delim(j) then ad=false

              end for

              'replace with Next J if ad=true then tmp=tmp & s2split(i) else f(fpos)=tmp tmp="" fpos += 1 'New feature in VB.NET 2005 redim preserve f(fpos) 'preserve means that increasing f and saving the ' 'previous data end if

              end for

              'replace with Next I Reuven

              C Offline
              C Offline
              charchabil03
              wrote on last edited by
              #6

              Dear Reuven Well no more erros in the code ( thx for that) but the thing is that ,how can i display the Data?each part alone?should add it to array ? it will be helpfull if i get ur mail such as Msn email or kindly add me : abouelrim@hotmail.com

              Regards Ramy

              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