Skip to content

Commit fe93cf9

Browse files
committed
完善main中调用所有函数
1 parent b3fced4 commit fe93cf9

File tree

4 files changed

+94
-313
lines changed

4 files changed

+94
-313
lines changed

main

679 Bytes
Binary file not shown.

main.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <string.h>
55
using namespace CPPCOMMON;
66

7+
void PrintVec( vector<string> vec );
8+
79
int main()
810
{
911
cout << "\n#===========Demo===========#\n" << endl;
@@ -13,6 +15,7 @@ int main()
1315
cout << "string_format()的结果:" << string_format( "This is [%s].\n", str.c_str() ) << endl;
1416
cout << endl;
1517

18+
1619
//StripStr 删除首部和尾部的'\n'和'\t' string StripStr(const string& str, const string& patternstr = " \n\t");
1720
str = "nanjing ";
1821
cout << "StripStr( str )之前:" << str << "$" << endl;
@@ -31,6 +34,65 @@ int main()
3134
cout << endl;
3235

3336

37+
//Split 划分字符串 vector<string> SplitStr(const string& source, const string& pattern)
38+
vec.clear();
39+
str = "nanjing\tyangzhou\tshanghai";
40+
vec = SplitStr( str, "\t" );
41+
//vec = SplitStr( str ); //默认为" ", "\t", "\n"其中一个,而且只能默认一个
42+
cout << "SplitStr()的结果为:" << endl;
43+
PrintVec( vec );
44+
cout << endl;
45+
46+
47+
//UpperStr 字母大写 string UpperStr(const string& strIn)
48+
str = "nanjing";
49+
cout << "UpperStr()之后的结果为:" << UpperStr( str ) << endl;
50+
cout << endl;
51+
52+
53+
//LowerStr 字母小写 string LowerStr(const string& strIn)
54+
str = "NanJing";
55+
cout << "LowerStr()之后的结果为:" << LowerStr( str ) << endl;
56+
cout << endl;
57+
58+
59+
//ReplaceStr 替换前几个字符串 string ReplaceStr(const string& strSrc, const string& oldStr, const string& newStr, int count)
60+
str = "beijingbeijingnanjingbeijing";
61+
string oldStr = "bei";
62+
string newStr = "nan";
63+
int count = 2;
64+
res = ReplaceStr( str, oldStr,newStr, 2 ); //只替换前2个"bei"
65+
cout << "ReplaceStr替换str之前:" << str << endl;
66+
cout << "replaceStr替换str之后:" << res << endl;
67+
cout << endl;
68+
69+
70+
//CountStrDistance 计算两个字符串间的距离 unsigned int CountStrDistance(const string& A, const string& B)
71+
string strA = "beijing";
72+
string strB = "nanjing";
73+
string strC = "yangzhou";
74+
cout << "CountStrDistance( nanjing => beijing ): " <<CountStrDistance( strA, strB ) << endl;
75+
cout << "CountStrDistance( nanjing => 'yangzhou ): " <<CountStrDistance( strC, strB ) << endl;
76+
cout << endl;
77+
78+
79+
//CountStrSimilarity 计算两个字符串间的相似个数 unsigned int CountStrSimilarity(const string& A, const string& B)
80+
cout << "CountStrSimilarity( nanjing => beijing ): " <<CountStrSimilarity( strA, strB ) << endl;
81+
cout << "CountStrSimialrity( nanjing => 'yangzhou ): " <<CountStrSimilarity( strC, strB ) << endl;
82+
cout << endl;
83+
3484

3585
return 0;
3686
}
87+
88+
89+
90+
91+
void PrintVec( vector<string> vec )
92+
{
93+
vector< string >::iterator iter = vec.begin();
94+
for( ; iter != vec.end(); iter++ )
95+
{
96+
cout << *iter << endl;
97+
}
98+
}

0 commit comments

Comments
 (0)