Click to See Complete Forum and Search --> : string to array


kuk
May 21st, 2002, 09:43 AM
I have a string something like this "May-90,June-91,July-92,", how do I separate the character from the integer and store it in an array

jparsons
May 21st, 2002, 09:45 AM
Originally posted by kuk
I have a string something like this "May-90,June-91,July-92,", how do I separate the character from the integer and store it in an array

I am a little bit confused by your question. Can you show us what you wouldl ike the array to hold after you convert it?

kuk
May 21st, 2002, 09:51 AM
My string array should look something like this

strarray[] = {"May","June","July"};

and

intarray[] = {90,91,92};

jparsons
May 21st, 2002, 10:04 AM
Originally posted by kuk
My string array should look something like this

strarray[] = {"May","June","July"};

and

intarray[] = {90,91,92};
Best solution to this looks like a parsing one. Scroll through the string. At each character use isalpha and isdigit to determine whether it's a number or letter. Once you find a number followed by anthing else, take the value you've stored and put it in the int array. Do the same for letters followed by numbers.