Solved

string parse

Posted on 2002-06-24
6
179 Views
Last Modified: 2010-05-02
Whats the most efficient way to parse a string like this..

1,2,3,4,5

I need to remove the commas and assign each number to an element in an array.


thanks,


knoxxx
0
Comment
Question by:JohnnyKnoxville
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7106084
arrMyArray = Split("1,2,3,4,5",",")

Anthony
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7106197
to be only slightly more complete:

Dim arrMyArray() as Integer
arrMyArray = Split("1,2,3,4,5",",")

0
 
LVL 3

Expert Comment

by:mastallama
ID: 7106601
Dim arrMyArray() as Integer
Dim myNumbers as String
arrMyArray = Split(myNumbers,",")


this let's you split from a variable instead of hard coding the numbers into the Split function.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 7106742
Indeed you should use split, however there is a limitation that Arthur has missed and mastallama has also missed (or copied from Arthur).

The array that you split to can only be declared as String or implicitly as variant which will get a subtype of String Array.

Dim arrMyArray() As Integer

Will generate a runtime error - 13 Type Mismatch

Dim arrMyArray() As String

Will not, likewise you could declare

Dim arrMyArray As Variant

0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7107108
TimCoffee, good catch.  What I posted was competely off the top of my head, as I did not have VB immediately available, so I could not test the code before I posted it.  Thanks.
0
 

Author Comment

by:JohnnyKnoxville
ID: 7130957
Excellent,

Thanks everyone for the help.


Knoxxx
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question