• <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 | 肖偉立
            国产精品日韩欧美久久综合| 一日本道伊人久久综合影| 久久亚洲精品人成综合网| 久久亚洲中文字幕精品有坂深雪| 亚洲AV日韩精品久久久久久| 麻豆成人久久精品二区三区免费 | 亚洲国产综合久久天堂| 国产ww久久久久久久久久| 日日狠狠久久偷偷色综合0| 伊人久久大香线蕉av不卡| 久久中文字幕一区二区| 久久久久久久久波多野高潮| 久久精品国产99国产电影网 | 色综合久久无码五十路人妻| 久久精品免费一区二区三区| 天天影视色香欲综合久久| 久久棈精品久久久久久噜噜| 午夜精品久久久久9999高清| 狠狠色丁香婷婷综合久久来| 中文字幕乱码人妻无码久久| 欧美激情精品久久久久久| 亚洲综合久久综合激情久久| 久久久久久久人妻无码中文字幕爆 | 狠狠精品久久久无码中文字幕 | 精品综合久久久久久97超人| 人人狠狠综合88综合久久| 精品国产一区二区三区久久| 亚洲国产精品成人久久| 日本高清无卡码一区二区久久| 97久久香蕉国产线看观看| 日韩十八禁一区二区久久| 久久91精品久久91综合| 97久久超碰国产精品旧版| 亚洲精品蜜桃久久久久久| 久久久久久久久久久久久久| 亚洲伊人久久成综合人影院 | 久久精品国产精品亚洲下载| 久久久久亚洲AV无码专区体验 | 伊人色综合久久| 青青青青久久精品国产| 九九久久99综合一区二区|