Hi,
I have a string of alphanumeric characters.Iwant to access alphabets in character array and numerals in an int array, simultaneously.how should i go ahead.
thanxxxxxxxx
Hi,
I have a string of alphanumeric characters.Iwant to access alphabets in character array and numerals in an int array, simultaneously.how should i go ahead.
thanxxxxxxxx
I'm afraid I don't understand your problem description. Can you elaborate?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Code:if( isdigit(alphanumstring[index]) ) { // choose numeric array } else if ( isalpha(alphanumstring[index]) ) { //choose alpha array } else { //not alpha or numeric ... do something else }
I think that he wants to break the string into two arrays, one with chars and the other with int.
Code:#include <algorithm> #include <functional> #include <string> #include <vector> #include <ctype> //inside a function: string mixedString; //fill mixed string with data vector<int> integerArray; vector<char> characterArray; //put all digits at the end string::iterator pos=remove_if(mixedString.begin(), mixedString.end(), ptr_fun(isdigit) ); //copy the digits to int array copy(pos, mixedString.end(),back_insert_iterator(integerArray)); //convert ascii digits to numbers for_each(integerArray.begin(), integerArray.end(), bind2nd(minus<char>(),'0')); //copy the non numbers to the character array. copy(mixedString.begin(),pos,back_insert_iterator(characterArray));
Last edited by King Mir; 07-06-2007 at 01:48 PM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.