Tuesday, 3 February 2015

Replace spaces in string by %20

 
#include<iostream>

int main()
{
  std::string s="HAI HOW ARE YOU !";
  int pos=s.find(" ");
  while(pos != std::string::npos)
  {
    s.erase(pos,1);
    s.insert(pos,"20");
    pos=s.find(" ");
  }
  std::cout<<s;
  return 0;
}