Using Split can be resolved the problem
Main Topics
Browse All TopicsHi
I have a string that contains a long list of stock codes separated by commas. What i need to do is this:
1. Count the no of stock codes in the list
2. For every 10 stock codes in the list, create a new string containing just those 10 codes. If there were 33 codes in the initial string there would be 3 strings containing 10 codes and 1 string containing 3 codes.
3. Create an array containing the new strings
I can think of many ridiculously convoluted ways of doing this but i would be interested to see a efficient way of doing this.
Thanks in advance
andrea
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
My only criticism of ericwong27's code is that it requires converting the string to an array, and then into some strings in an array.
But it should be faster if the split doesn't take too long.
I suppose if you went with my "code", you could just maintain an offset in the original string as the new start position for each "find the next ," step. That would need you read from the original string and populate the appropriate array entry and only have a few integers to keep track of.
Business Accounts
Answer for Membership
by: RQuadlingPosted on 2008-05-05 at 14:57:00ID: 21503339
I don't know vb, but here is a pseudo code mechanism.
Declare empty array of strings.
Declare a reference to 1 to indicate which array entry we are using.
Declare a count for the current number of items processed.
loop
Find position of comma.
If the current count is > 0 add a comma to the array entry.
Copy everything to the left of the comma to the array entry.
Truncate the data string to the next character after the comma.
Add 1 to the current count.
If the current count is 10, reset the count to 0 and add 1 to the array reference
If there is nothing left to check, drop out of the loop.
End loop