stl을 쓰다보니, 간단하게 upcase, locase를 쓰길를 희망하는데,
마땅한게 없다...--;; 이걸 응용해서 다른 것들도 만들어서 쓰면 될 것 같다.
std::string upcase(const std::string& s) { std::string s2(s); for(unsigned int ii = 0; ii < s2.length(); ii++) s2[ii] = toupper(s2[ii]); return s2; } // Allows multiple filters separated by ';' bool testCall(string file, string _filter) { std::string strOrgName(upcase(pszOrgName)); std::string strCompare(upcase(g_filelist[i])); if(strCompare.find(strOrgName) != std::string::npos) { ::OutputDebugString("발견"); } }
이것 보다 간단한 방법이 하나 있다고 해서 사용한 적이 있는데,눈으로 봤을때는 strlwr()을 사용하는 점이 다를 뿐, 이상이 없는 것 처럼 보였다...
한참 지나고 나서 알게 된 사실은 이건 stl에서 권장하는 방법이 아니었다...
왜냐하면, strlwr은 C/C++ 표준함수도 아닐뿐더러...
원본데이터를 손상시키는 Inplace 변환 방법이기 때문이다.
(참고: http://kin.naver.com/db/detail.php?d1id=1&dir_id=10104&eid=SrteUU3y93FnHnKrnI5NjX7FhSvZO33P )
std::string mvalue(*arrayitem[i]); std::string mlowvalue(strlwr((char*)mvalue.c_str())); if(strCompare.find(strOrgName) != std::string::npos) { ::OutputDebugString("발견"); }
표준을 지키며 사용하는 방법은 다음과 같다.#include <iostream> #include <string> #include <algorithm> #include <cstdlib> using namespace std; int main() { std::string mvalue("TesT"); std::string mlowvalue(mvalue); transform(mvalue.begin(), mvalue.end(), mlowvalue.begin(), tolower); if(strCompare.find(strOrgName) != std::string::npos) { ::OutputDebugString("발견"); } }
이상...
댓글
댓글 쓰기