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
Printable View
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?
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));