回复 "Globe" 关于 XML 编码转换的问题
2011-04-01 22:32
561 查看
问题来源:http://www.cnblogs.com/del/archive/2011/03/24/1994029.html#2059114
Globe 同学有这样的 XML 文件:
其中包含中文、韩文,并且有些是十六进制、有些是十进制,真实的内容应该是:
下面是把它打开并另存为标准的 UTF-8 格式 XML 的代码(使用了 DelphiXE 最新的正则表达式组件):
Globe 同学有这样的 XML 文件:
其中包含中文、韩文,并且有些是十六进制、有些是十进制,真实的内容应该是:
下面是把它打开并另存为标准的 UTF-8 格式 XML 的代码(使用了 DelphiXE 最新的正则表达式组件):
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, RegularExpressions; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private function MyMatchEvaluator(const Match: TMatch): string; public end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const pattern = '?[0-9A-Fa-f]{1,5};'; var List: TStringList; reg: TRegEx; path,tmpName: string; begin with TOpenDialog.Create(nil) do begin Execute; path := FileName; Free; end; if path = '' then Exit; List := TStringList.Create; List.LoadFromFile(path); List.Text := StringReplace(List.Text, 'GB2312', 'UTF-8', [rfIgnoreCase]); reg := TRegEx.Create(pattern, [roCompiled]); List.Text := reg.Replace(List.Text, MyMatchEvaluator); tmpName := ExtractFileName(path); path := StringReplace(path, tmpName, 'UTF8_' + tmpName, [rfIgnoreCase]); Text := path; List.SaveToFile(path, TEncoding.UTF8); List.Free; end; function TForm1.MyMatchEvaluator(const Match: TMatch): string; begin Result := Match.Groups[1].Value; if Match.Value[3] = 'x' then Result := '$' + Result; Result := WideChar(StrToInt(Result)); end; end.
相关文章推荐
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 关于struts2的xml中<result type="redirect">参数问题
- 关于文本编码格式转换的问题
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 使用 idHTTP 获取 UTF-8 编码的中文网页 - 回复同学 "Delphi学习者" 的问题
- c语言中关于utf-8编码转换为gb2312的问题
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 关于显示透空歌词的思路 - 回复 "zhaoboaidelphi" 的问题
- 使用 idHTTP 获取 UTF-8 编码的中文网页 - 回复同学 "Delphi学习者" 的问题
- 使用 BinToHex() 把 TBytes 转换为十六进制字符串 - 回复 "梧桐栖凤" 的问题
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- 解决Excel 2007的"有 XML 错误的 /xl/sharedStrings.xml"问题 (“发现不可读取的内容,是否回复此工作薄的内容...")
- 关于xml的编码问题
- 关于PHP在数组对象与JSON数据之间的转换问题(编码问题)
- 把流中的字符串转换为 UTF 格式 - 回复 "lostapple" 的问题
- 关于“XML创建者Tim Bray 认为.NET三大问题”的回复
- 编程语言的学习 ------ python3 关于编码的转换问题