469,632 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Split String

89
Hi all I have a simple problem with string. I want to split string, such as:
dim s as string
dim k(3) as string
s="aa1,bv1,cc1,dt1"

i want to split the value in k,
k(0)=aa1
k(1)=bv1
k(2)=cc1
k(3)=dt1

Pls give me any easy idea to solve it, thx advance
Jan 2 '08 #1
5 2282
Torgg
41
You almost had it, give this a try... I tested it and it worked.

Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2. Dim k() As String
  3. s = "aa1,bv1,cc1,dt1"
  4. k = Split(s, ",")
  5.  
  6. MsgBox k(0)
  7. MsgBox k(1)
  8. MsgBox k(2)
  9. MsgBox k(3)
Hope this helps,
Torgg
Jan 3 '08 #2
shaiful
89
You almost had it, give this a try... I tested it and it worked.

Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2. Dim k() As String
  3. s = "aa1,bv1,cc1,dt1"
  4. k = Split(s, ",")
  5.  
  6. MsgBox k(0)
  7. MsgBox k(1)
  8. MsgBox k(2)
  9. MsgBox k(3)
Hope this helps,
Torgg

Thx a lot Torgg, its working
Jan 3 '08 #3
shaiful
89
Thx a lot Torgg, its working
I have one one more question about this split string. if string is:
s="a12.b2.c2.d.e.f2........"
and how i will get all those data from s, because i dont know how many total data in there. if i use like as u said k(0), k(1)..... but if s is finished and its say Error, so do i=u have any idea abt this pls, thx again
Jan 3 '08 #4
CyberSoftHari
487 Expert 256MB
You will use
Expand|Select|Wrap|Line Numbers
  1. Dim k(10) as String
did you tried ReDim ..?
Note: Try your self a bit more and post your query. Doing homework is prohibited here and you have to read posting guidelines.
Jan 3 '08 #5
I have one one more question about this split string. if string is:
s="a12.b2.c2.d.e.f2........"
and how i will get all those data from s, because i dont know how many total data in there. if i use like as u said k(0), k(1)..... but if s is finished and its say Error, so do i=u have any idea abt this pls, thx again
It can be checked using UBound as under:

Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2. Dim k() As String
  3. s = "aa1,bv1,cc1,dt1"
  4. k = Split(s, ",")
  5.  
  6. for i=0 to UBound(k)
  7.     MsgBox k(i)
  8. next i
Hope your problem is solved with this.
Jan 3 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Stu Cazzo | last post: by
11 posts views Thread by Carlos Ribeiro | last post: by
6 posts views Thread by Senthil | last post: by
4 posts views Thread by Itzik | last post: by
4 posts views Thread by Crirus | last post: by
5 posts views Thread by kurt sune | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.