Solved

string parse

Posted on 2002-06-24
6
141 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
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now