全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1654
推到 Plurk!
推到 Facebook!

Delphi Unicode

 
is_tem
一般會員


發表:17
回覆:15
積分:11
註冊:2002-04-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-03-27 21:58:30 IP:218.103.xxx.xxx 訂閱
In VB, VC Net,
System.Text.Encoding.Unicode.GetBytes("中文字")

In Delphi, how?
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-03-29 09:35:29 IP:121.35.xxx.xxx 訂閱
<textarea class="delphi" rows="10" cols="60" name="code">procedure TForm1.Button1Click(Sender: TObject); var s: WideString; c: integer; i: Integer; begin s := '中文字'; for i := 1 to Length(s) do begin c := Ord(s[i]); Edit1.Text := Edit1.Text IntToStr(c shr 8) ', ' IntToStr(c and $FF) ', '; end; end;</textarea><br />
希望有更好的方法!

<textarea class="c#" rows="10" cols="60" name="code"> using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "中文字"; byte[] bts = System.Text.Encoding.Unicode.GetBytes(s); PrintHexBytes(bts); Console.ReadLine(); } public static void PrintHexBytes(byte[] bytes) { if ((bytes == null) || (bytes.Length == 0)) Console.WriteLine(""); else { for (int i = 0; i < bytes.Length; i ) Console.Write("{0:X2} ", bytes[i]); Console.WriteLine(); } } } } </textarea>
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-03-29 14:26:11 IP:219.134.xxx.xxx 訂閱
Sorry, 前面寫倒了,正確的應該是:

<textarea class="delphi" rows="10" cols="60" name="code"> procedure TForm1.Button1Click(Sender: TObject); var s: WideString; c: integer; i: Integer; begin s := '中文字'; for i := 1 to Length(s) do begin c := Ord(s[i]); Edit1.Text := Edit1.Text IntToStr(c and $FF) ', ' IntToStr(c shr 8) ', '; end; end; </textarea>
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
系統時間:2024-05-14 15:41:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!