Link to home
Start Free TrialLog in
Avatar of schwientekd
schwientekdFlag for United States of America

asked on

First occurence in For Each statement

I've got a For Each statement written in visual studio using vb.  It takes a comma separated statement and runs something on each item separated by the commas.  I need to do something special with the first item.  How could I do this?
ASKER CERTIFIED SOLUTION
Avatar of learning_t0_pr0gram
learning_t0_pr0gram

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another way to do this would be to use a String Array.  Something like this:

dim commastring as String = "thingone, thingtwo, thingthre, blaj"
dim StrArr() as String
StrArr = Split(commstring,",")    <---this creates a String Array using the comma in your original string to as a separator


Now, you can do whatever you'd like to the first thing by refering to it directly - outside of the context of a loop.

StrArr(0) (which in the example I've shown here would be equal to "thingone"

And to loop through your string array you could do:

dim i as Integer = 0
for i = 0 to ubound(StrArr)

next
Avatar of schwientekd

ASKER

Worked perfect.  Thanks for the quick response.