-
String character removal
Hi,
I know how to remove certain characters from a string by using something like this:
Code:
string str ("Hello world!");
erase (0, 6);
That's great if I want to do that manually, but say if someone entered a string, how would I automatically remove every other character they entered? Sorry if this is a poor explanation, but I hope someone can help me.
-Joe
-
Going to guess this is for an assignment. I am also going to guess that your class just taught you about loops. So... think of an implementation with loops that will remove every other character.
-
Unfortunately my school doesn't teach programming, stuck doing it alone. But thanks for the advice
-
Ah, well then here is some reading for you sir to help you in your learning :)
For loops:
for loop - cppreference.com
While loops:
while loop - cppreference.com
do-while loops:
do-while loop - cppreference.com
You can use any of these 3 to easily accomplish your goal here. I am not trying to be rude, I'm trying to help you without flat out giving you the answer.
Also for general reference:
C++ reference - cppreference.com
-
For a quick and easy strategy, use the STL to your advantage. The <algorithm> header is one of my favorites: remove_if - C++ Reference