C語言,擷取帶有漢字 字母的字串函式

2021-08-24 22:39:00 字數 459 閱讀 8879

在工作中,遇到要擷取字串在螢幕上顯示出來,因為字串帶有漢字,如果擷取不好,會引起亂碼,寫了下面的函式

在uclinux下與vc6.0中測試可以通過。

/*擷取字串 name :要擷取的字串 store:要儲存的字串 len:要擷取的長度 */ void split_name( char * name , char * store , int len ) ; if ( strlen(name)>7&1 && name[i+1]>>7&1 ) //if ( name[i] < 0 && name[i+1] < 0 ) i = i + 2 ; else i = i + 1 ; } i = i > len ? i-3 :i-1; strncpy( store , name , i+1 ); //擷取前i+1位 *(store+i+1)=0; strcpy( strtemp , name + i + 1 ); strcpy( name , strtemp ); }

C 中漢字字串的擷取

g main.cpp 進行編譯。為了解決限定長度的賦值,如果出現半個中文,則採取截斷措施,解決中文亂碼問題。include include include using namespace std define max size 32 int chinese split std string str,...

C 中漢字字串的擷取

1 複製 如下 const char str test測試test while str else 2 參看下面的字串轉換函式。複製 如下 用getbytes encoding 返回字串的乙個byte陣列 當b 0 為 63時,應該是轉碼錯誤 a 不亂碼的漢字字串 1 encoding用gb2312時...

擷取包含漢字字串的子字串

擷取字串 本書字數 209.9萬字 中間的數字209.9 char test 10 測試 printf s d n test,int strlen test 得到結果是6也就是說每個漢字占用6個字元 然後測試目標字串的大小 char strlen tmp 40 本書字數 209.9萬字 printf...