how do i take into account the white spaces in a string?

Hi people, as i am doing an encryption program on a playfair cipher. I am now stuck on a problem on decryption.

If my string is helloworld (without a space), it will decrypt normally.
However , if my string has a space in between it. Let`s say Hello World, it will not decrypt normally.

How do i take into account the space that is in between hello & world?

example: hello world

Thanks in advance
have you tried isspace()?
http://www.cplusplus.com/reference/cctype/isspace/
ex:
1
2
string str = "Hello World";
for(unsigned int i = 0; i<str.size(); i++) if(isspace(str[i])) str.erase(i,1);
yes i have tried isspace. However, it removes the space in between it, i want to maintain the space in the cipher text when i decrypt it too

example : hello world = hello world

if i use isspace, it removes the space. I want to maintain the orignal text as above.

its driving me nuts lol
Last edited on
I thought you were trying to get rid of the space...kind of hard to tell you your problem without any code we don't even know how you are encrypting or decryping the text.
it could be something simple like this
1
2
3
4
5
6
string str = "Hello World"; 
cout << "Before Encrypt: " << str << endl;
for(unsigned int i = 0; i<str.size(); i++) str[i]++; // encrypt
cout << "After Encrypt: " << str << endl;
for(unsigned int i = 0; i<str.size(); i++) str[i]--; //decrypt
cout << "After Decrypt: " << str << endl;

and you would get an output of

Before Encrypt: Hello World
After Encrypt: Iffmmp!Xpsme
After Decrypt: Hello World


Or you could have a much more advanced encrypter/decrypter
Last edited on
sorry about that, the code is way too lengthy to be posted here. I will give it a try! thanks for your help!
Topic archived. No new replies allowed.