to add something in place of spaces in a string

PHOTO EMBED

Thu Jun 27 2024 11:32:01 GMT+0000 (Coordinated Universal Time)

Saved by @vishnu_jha #c++ #dsa #string

#include <iostream>
#include <string>
using namespace std;

string addInplaceOfSpaces (string &s) {
  string temp = "";
  for (int i = 0; i < s.length(); i ++) {
    if (s[i] == ' ') {
      temp.push_back('@');
      temp.push_back('2');
      temp.push_back('3');
    }
    else {
      temp.push_back(s[i]);
    }
  }
  return temp;
}

int main() {
  string s ="my name is vishnu deb jha" ;
  string v = addInplaceOfSpaces(s);
  cout << v << endl;
  return 0;
}
// output is my@23name@23is@23vishnu@23deb@23jha
content_copyCOPY

https://youtu.be/Wdjr6uoZ0e0