First of all I'm really if i posted this here, when there is another topic about this. I can't seem to find it, and I'm really desperate to find the answer, or just a hint on how to do it.
Yesterday we were told to make a Program that will segregate/separate a single string that contains alphanumeric symbols. Then the values will be copied to a specific label.
Ex Output:
Enter a String: 1ILOVEYOU43
Numbers Only: 143
Letters Only: ILOVEYOU
I'm really just a beginner though I know how to manipulate a program once a get a hint on how to do it. We were also told to include the "duration" of the segregation.
I've done some research, and I get results about String find, copy, erase and etc. but I cant seem to integrate it with the codes above, the codes provided in my searches are as follows:
#include <iostream>
#include <string>
#include <algorithm>
usingnamespace std;
int main ()
{
string str("C++ is best language");
int pos1, pos2; // size_t or size_type
// work not correct
// search for first string "best" inside of str
// default position is 0
pos1 = str.find ("best");
cout << "Word best is found on position " << pos1+1
<< endl;
// if pattern is not found - return -1
pos2 = str.find ("best",pos1+1);
cout << "Word best is found on position " << pos2+1
<< endl;
// search for first occurrence of character
pos1 = str.find('g');
cout << "First character 'g' found on position "
<< pos1
<< endl;
// search for first occurrence of string
string s = "is";
pos1 = str.find (s);
cout << "Word 'is' is found on position " << pos1+1
<< endl;
return 0;
}
string::find returns the index into the string of the match, or string::npos if it did
not find a match. You can print the Nth character of a string like this:
Keep it simple always!!!!!!!
u kow ASCII code 48 up to 57 are numbers!! , I wont do your homework. If working with string type, there's always a c_str() Function, think!!!!! u needa gather two diffrent character set and they got distinct values, make a choise... Trust it it's not that complicated!!!