• <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 閱讀(2205) 評論(1)  編輯 收藏 引用 所屬分類: Delphi

            評論

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

            請教一下QQ:36026877可以加QQ嗎?
            2012-06-06 20:34 | 肖偉立
            久久99精品久久久久久| 亚洲国产成人精品91久久久| 亚洲欧美成人综合久久久| 99精品久久久久中文字幕| 91久久精品视频| 久久亚洲精品无码aⅴ大香| 狠狠色婷婷久久一区二区三区| 91久久精品国产成人久久| 久久久久久久综合狠狠综合| 四虎国产精品免费久久5151| 久久久久久精品免费看SSS| 日本久久久久久中文字幕| 色婷婷综合久久久中文字幕 | 亚洲AV无码成人网站久久精品大| 久久99国内精品自在现线| 久久只有这里有精品4| 99久久亚洲综合精品成人| 久久久久亚洲AV无码观看| 久久亚洲国产精品123区| 久久99毛片免费观看不卡| 午夜精品久久久久久久| 三级三级久久三级久久| 亚洲国产成人久久精品99| 国产成人久久777777| 久久综合中文字幕| 国产精品18久久久久久vr| 欧美精品久久久久久久自慰| 区久久AAA片69亚洲| 中文精品99久久国产| 久久久这里有精品| 久久精品国产亚洲AV影院| 2021久久精品免费观看| 狠狠色丁香久久婷婷综合| 久久久久99这里有精品10| 久久综合亚洲鲁鲁五月天| 伊人久久综合无码成人网| 精品国产乱码久久久久久人妻| 99久久国产宗和精品1上映| 色妞色综合久久夜夜| 99久久精品费精品国产一区二区| 97久久精品午夜一区二区|