473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 2519
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

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

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
4
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
4
by: Crirus | last post by:
There is a function somewhere to split a string with multiple tokens at a time? Say I have this: aaaa#bbbbb*ccccc$dddd I whould like to split it so the result whould be aaaa bbb
14
by: Ron | last post by:
Hello, I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? .... data += ASCII.GetString(buffer, 0,...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.