剑指OFFER 替换空格

剑指OFFER 替换空格

class Solution {
public:
	void replaceSpace(char *str,int length) {
        string s(str);

        size_t pos;
        while( (pos = s.find(' ')) != string::npos )
        {
            s.replace(pos,1,"%20");
        }
        
        
        for(int i=0;i<s.size();i++)
        {
            str[i]=s[i];
        }
        str[s.size()] = '\0';
        
        return;
	}
};
posted @ 2020-01-17 08:36  virgil_devil  阅读(80)  评论(0编辑  收藏  举报