728x90
sqlite ' 포함된 문자열(i'm fine) insert시 에러가 발생함으로 변환 필요
std::string StrConvert::ReplaceAll(std::string& str, const std::string& from, const std::string& to)
{
size_t start_pos = 0; //string처음부터 검사
while ((start_pos = str.find(from, start_pos)) != std::string::npos) //from을 찾을 수 없을 때까지
{
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // 중복검사를 피하고 from.length() > to.length()인 경우를 위해서
}
return str;
}
std::cout << ReplaceAll(string("Number Of Beans"), std::string(" "), std::string("_")) << std::endl;
std::cout << ReplaceAll(string("ghghjghugtghty"), std::string("gh"), std::string("X")) << std::endl;
std::cout << ReplaceAll(string("ghghjghugtghty"), std::string("gh"), std::string("h")) << std::endl;
#결과
Number_Of_Beans
XXjXugtXty
hhjhugthty
참조
728x90
'언어 > C++' 카테고리의 다른 글
sqlite3 테이블 확인 (0) | 2021.04.12 |
---|---|
C++ UTF-16 formatstring 하기(swprintf 함수 사용) (0) | 2021.03.12 |
C++ 시간 계산 (0) | 2021.03.11 |