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