By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Split String

P: 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
Share this Question
Share on Google+
5 Replies


P: 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

P: 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

P: 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

Expert 100+
P: 487
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

P: 46
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.