Remove Spaces from String
C++
Medium
4 views
Problem Description
Delete all space characters from string.
Real Life: Cleaning up user input.
Step-by-Step Logic:
1. Create new string
2. Copy only non-space characters
3. Skip space characters
4. Return cleaned string
Official Solution
void string_q7_remove_spaces() {
string text = "Hello World Programming";
string result = "";
cout << "Original: " << text << endl;
for(int i = 0; i < text.length(); i++) {
if(text[i] != ' ') {
result += text[i];
}
}
cout << "After removing spaces: " << result << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!