• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠,我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數據加載中……

            關于Utf8編碼的幾個函數

            最近一段時間老弄Utf8編碼,工作時寫了幾個函數,給大家指正一下

            //////////////////////////////////////////////
            //---------取得utf8字符的長度---------------//
            //Str:String 源字符串
            //Result:Integer utf8字符串長度
            class function TPduPush.getUTF8Len(Str: string): Integer;
            var
            i: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            result := 0;
            while i < length(tmpChar) do begin
            if ord(tmpChar[i]) < $80 then begin
            i := i + 1;
            result := result + 1;
            end else begin
            i := i + 2;
            result := result + 3;
            end;
            end;
            end;

            ////////////////////////////////////////////////
            //----------取得字符串中的字符個數------------//
            //str:String 源字符串
            //Result:Integer 字符個數,兼容中文雙字節
            class function TPduPush.getAnsiLen(Str: string): integer;
            var
            i: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            result := 0;
            while i < length(tmpChar) do begin
            if ord(tmpChar[i]) < $80 then
            i := i + 1
            else
            i := i + 2;
            result := result + 1;
            end;
            end;


            /////////////////////////////////////////////////
            //---------截取指定長度的utf8字符串------------//
            //str:string 源字符串
            //count:Integer 指定長度 一個漢字占三個字節,長度只能小,不能大
            //Result:string 截取后的utf8字符串
            class function TPduPush.getUTF8String(Str: string; count: Integer): string;
            var
            i, j: integer;
            tmpChar: Pchar;
            begin
            tmpChar := pchar(str);
            i := 0;
            j := 0;
            result := '';

            while i < length(tmpChar) do begin
            if j >= count then break; //英文轉碼后不能超過指定的位數
            if ord(tmpChar[i]) < $80 then begin
            result := result + string(tmpChar[i]);
            i := i + 1;
            j := j + 1;
            end else begin
            if j + 2 >= count then break; //漢字轉碼后不能超過指定的位數
            result := result + string(tmpChar[i]) + string(tmpChar[i + 1]);
            i := i + 2;
            j := j + 3;
            end;
            end;
            end;

            posted on 2006-01-19 15:06 Khan 閱讀(2193) 評論(1)  編輯 收藏 引用 所屬分類: Delphi

            評論

            # re: 關于Utf8編碼的幾個函數  回復  更多評論   

            請教一下QQ:36026877可以加QQ嗎?
            2012-06-06 20:34 | 肖偉立
            久久天天躁狠狠躁夜夜96流白浆| 久久久久国产精品| 一本久久免费视频| 97精品伊人久久久大香线蕉 | 色欲综合久久中文字幕网| 久久人人爽爽爽人久久久| 岛国搬运www久久| 亚洲愉拍99热成人精品热久久| 99精品国产在热久久| 亚洲国产高清精品线久久| 久久亚洲国产成人精品性色| 日本加勒比久久精品| 精品久久一区二区三区| 久久人做人爽一区二区三区| 91久久精品无码一区二区毛片| 人人妻久久人人澡人人爽人人精品| 久久99精品国产一区二区三区| 人妻丰满AV无码久久不卡| 亚洲国产成人久久一区WWW| 国产精品久久久久aaaa| 久久这里的只有是精品23| 伊人久久大香线蕉精品| 精品熟女少妇av免费久久| 久久久国产打桩机| 看全色黄大色大片免费久久久| 亚洲欧美日韩精品久久| 97精品伊人久久大香线蕉app| 囯产极品美女高潮无套久久久| 欧美久久久久久精选9999| 狠狠色伊人久久精品综合网| 久久91精品国产91久久麻豆| 久久久久久九九99精品| 亚洲级αV无码毛片久久精品| 伊人久久大香线蕉精品不卡 | 久久久久亚洲精品无码蜜桃| 中文国产成人精品久久亚洲精品AⅤ无码精品| 日本免费久久久久久久网站| 色成年激情久久综合| 久久精品国产黑森林| 亚洲欧美另类日本久久国产真实乱对白| 久久一区二区三区免费|