update str_functs.cpp

This commit is contained in:
gwdwyy 2013-07-11 13:56:29 +08:00
parent 48136abbd8
commit 28c3260d4c

View File

@ -27,18 +27,18 @@ namespace CPPCOMMON
string joinStr(const vector<string>& src, const string& connectorStr) string joinStr(const vector<string>& src, const string& connectorStr)
{ {
string res; string res = "";
string tmpStr; int len = src.size();
size_t len = src.size(); if(0 == len)
for(size_t i = 0; i < len - 1; i++) {
return "";
}
for(int i = 0; i < len - 1; i++)
{ {
res += stripStr(src[i]); res += stripStr(src[i]);
res += connectorStr; res += connectorStr;
} }
if(0 < len) res += stripStr(src[len-1]);
{
res += stripStr(src[len-1]);
}
return res; return res;
} }
vector<string> splitStr(const string& source, const string& pattern) vector<string> splitStr(const string& source, const string& pattern)
@ -362,7 +362,11 @@ int main()
string utfStr = unicodeToUtf8(uniStr); string utfStr = unicodeToUtf8(uniStr);
cout<<utfStr<<endl; cout<<utfStr<<endl;
} }
getchar(); vector<string> tmp;
tmp.push_back("1");
//tmp.push_back("2");
//tmp.clear();
cout<<joinStr(tmp, ",")<<endl;
return 0; return 0;
} }
#endif #endif