The first step, I changed the string to a lowercase, after that I removed all the non letters from the string, now I am struggling to replace each letter with the alphabet position. does anyone know how to do such a thing? Thank you!
string alphabet_position(string message){
string alphabet= "abcdefghijklmnopqrstuvwxyz";
int aplha_numbers[100];
for_each(message.begin(), message.end(), [](char & c){
c = ::tolower(c);
});
for(int i=0; i< message.size(); i++){
if(message[i] < 'a' || message[i] > 'z'){
message.erase(i, 1);
i--;
}
}
for(int j=0; j<message.size(); j++){
int index = alphabet.find(message[j]);
aplha_numbers[j]= index +1;
}
std::ostringstream os;
for(int z: aplha_numbers){
os<<z;
}
std::string str(os.str());
return str;
}
Now I have a different issue , I am getting the alphabet positions but I also get a lot of garbage values after the last letter. As an example Input: abc output 123 and after that a lot of numbers 32761004966.....