2013年5月1日 星期三

如何替換字串中的字元(C++)

#include < string >

int main(void)
{
 std::wstring name = L"abc-def\\xyz";
 int position = name.find(L"\\");
 while(position != name.npos)
 {
  name.replace(position, 1, L"-");
  position = name.find(L"\\", position + 1);
 }
}

沒有留言:

張貼留言