// C7_3.cpp : Defines the entry point for the console application. // 字串處理 #include "stdafx.h" #include #include int main(int argc, char* argv[]) { char MyStr_1[100]="Happy Birthday"; char MyStr_2[100]="Merry Christmas"; int ComR; int StrL; cout << "MyStr_1 = " << MyStr_1 << endl; cout << "MyStr_2 = " << MyStr_2 << endl; cout << "---------------------------------------" << endl; //strcpy() -- 字串取代 strcpy(MyStr_1,"Welcome C++ World"); strcpy(MyStr_2,"Visual C++"); cout << "執行函數 strcpy(MyStr_1,\"Welcome C++ World\") & strcpy(MyStr_2,\"Visual C++\")" << endl; cout << "MyStr_1 = " << MyStr_1 << endl << "MyStr_2 = " << MyStr_2 << endl << endl; //strset() -- 字串字元取代 strset(MyStr_2,'*'); cout<< "執行函數 strset(MyStr_2,'*') 後 :" << endl; cout<< " MyStr_2 = "<< MyStr_2 << endl << endl; //strcmp() -- 字串比較 ComR = strcmp(MyStr_1,MyStr_2); cout<< "執行函數 strcmp(MyStr_1,MyStr_2) 後 :" << endl; if(ComR==0) // 顯示結果 cout << "比較結果 : MyStr_1 = MyStr_2" << endl; else cout << "比較結果 : MyStr_1 != MyStr_2" << endl; //_stricmp() -- 字串比較 ComR =_stricmp(MyStr_1,MyStr_2); cout<<"執行函數 _stricmp(MyStr_1,MyStr_2) 後 :" << endl; if(ComR==0) cout<< "比較結果 : MyStr_1=MyStr_2" << endl; else cout<< "比較結果 : MyStr_1!=MyStr_2" << endl << endl; //strlen() -- 取得字串大小 StrL=strlen(MyStr_1); cout << "After strlen(MyStr_1)" << endl; cout << "字串 MyStr_1 大小為 : " << StrL << endl << endl; //strrev() -- 取得字串反轉結果 strrev(MyStr_1); cout<<"執行函數 strrev(MyStr_1) 後 :" << endl; cout<< "MyStr_1=" << MyStr_1 << endl << endl; //strupr() -- 字串內容改為英文大寫 cout<<"執行函數 strupr(MyStr_1) 後 :" << endl; strupr(MyStr_1); cout<< "MyStr_1 = " << MyStr_1 << " , MyStr_2 = " << MyStr_2 << endl << endl; //strlwr() -- 字串內容改為英文小寫 cout<<"執行函數 strlwr(MyStr_1) 後 :" << endl; strlwr(MyStr_1); cout<< "MyStr_1 = " << MyStr_1 << " , MyStr_2 = " << MyStr_2 << endl << endl; return 0; }