﻿{"id":736,"date":"2013-07-15T00:57:52","date_gmt":"2013-07-14T16:57:52","guid":{"rendered":"http:\/\/www.tansoo.cn\/?p=736"},"modified":"2014-09-11T01:01:15","modified_gmt":"2014-09-10T17:01:15","slug":"delphi2010%e4%b8%adansi%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%8eunicode%e5%ad%97%e7%ac%a6%e4%ba%92%e8%bd%ac%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.tansoo.cn\/?p=736","title":{"rendered":"Delphi2010\u4e2dAnsi\u5b57\u7b26\u4e32\u4e0eUnicode\u5b57\u7b26\u4e92\u8f6c\u65b9\u6cd5"},"content":{"rendered":"<p>Delphi2010\u53ca\u4ee5\u4e0a\u7248\u672c\u540e\uff0c\u9ed8\u8ba4\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u7531\u539f\u6765\u7684\u5355\u5b57\u8282Ansi\u578b\u6539\u6210\u4e86Unicode\u578b\uff0c\u9020\u6210\u539f\u6765\u7684\u4e00\u4e9b\u539f\u4ee3\u7801\u65e0\u6cd5\u8fd0\u884c\uff0c\u73b0\u63d0\u4f9b\u4e00\u4e2a\u4e92\u8f6c\u7684\u51fd\u6570\u4f9b\u5927\u5bb6\u4f7f\u7528\uff0c\u5728Delphi2010+WIN7\u4e0a\u8c03\u8bd5\u901a\u8fc7\u3002<\/p>\n<p>\u4e00\u3001Ansi\u578b\u8f6cUnicode\u578b<\/p>\n<pre class=\"lang:delphi decode:true \" >function AnsiToUnicode(Str: AnsiString): String;\r\nvar\r\n  Len: integer;\r\nbegin\r\n  Len := Length(Str) + 1;\r\n  SetLength(Result, Len);\r\n  Len := MultiByteToWideChar(CP_ACP, 0, PAnsiChar(Str), -1,\r\n    PWideChar(Result), Len);\r\n  SetLength(Result, Len - 1); \/\/ end is #0\r\nend;<\/pre>\n<p><!--more--><\/p>\n<p>\u4e8c\u3001Unicode\u578b\u8f6cAnsi\u578b<\/p>\n<pre class=\"lang:delphi decode:true \" >function UnicodeToAnsi(Str: String): AnsiString;\r\nvar\r\n  Len: integer;\r\nbegin\r\n  Len := Length(Str) * 2 + 1; \/\/ one for #0\r\n  SetLength(Result, Len);\r\n  Len := WideCharToMultiByte(CP_ACP, 0, PWideChar(Str), -1,\r\n    PAnsiChar(Result), Len, nil, nil);\r\n  SetLength(Result, Len - 1);\r\nend;<\/pre>\n<p>\u4e09\u3001\u8c03\u7528\u4e3e\u4f8b\uff1a <\/p>\n<pre class=\"lang:delphi decode:true \" >procedure TForm3.Button1Click(Sender: TObject);\r\nvar\r\n  ans: AnsiString;\r\n  Str: String;\r\n  I: integer;\r\nbegin\r\n  ans := UnicodeToAnsi(Edit1.Text);\r\n  I := 1;\r\n  while I &lt;= Length(ans) do\r\n  begin\r\n    Memo1.Lines.Add(IntToHex(ord(ans[I]), 2) + IntToHex(ord(ans[I + 1]), 2));\r\n    I := I + 2;\r\n  end;\r\n\r\n  I := 1;\r\n  Str := AnsiToUnicode(ans);\r\n  while I &lt;= Length(str) do\r\n  begin\r\n    Memo1.Lines.Add(IntToHex(ord(str[I]), 4));\r\n    I := I + 1;\r\n  end;\r\nend;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Delphi2010\u53ca\u4ee5\u4e0a\u7248\u672c\u540e\uff0c\u9ed8\u8ba4\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u7531\u539f\u6765\u7684\u5355\u5b57\u8282Ansi\u578b\u6539\u6210\u4e86Unicode\u578b\uff0c\u9020\u6210\u539f\u6765\u7684\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[13,14,3],"class_list":["post-736","post","type-post","status-publish","format-standard","hentry","category-program","tag-ansi","tag-delphi","tag-unicode"],"_links":{"self":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=736"}],"version-history":[{"count":0,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=\/wp\/v2\/posts\/736\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tansoo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}