- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用德尔福 6。
我想将葡萄牙语 UTF-8 编码的字符串解码为 WideString
,但我发现它没有正确解码。
原文为"ANÁLISE8"
.使用后UTF8Decode()
,结果为 "ANALISE8"
. "A"
顶部的符号消失。
这是代码:
var
f : textfile;
s : UTF8String;
w, test : WideString;
begin
while not eof(f) do
begin
readln(f,s);
w := UTF8Decode(s);
WideString
正确吗?
最佳答案
注意 UTF8Decode()
的实现在 Delphi 6 中是不完整的。具体来说,它不支持编码的 4 字节序列,这是处理 U+FFFF
以上的 Unicode 代码点所必需的。 .这意味着 UTF8Decode()
只能解码 UCS-2 范围内的 Unicode 代码点,而不是完整的 Unicode 轨道。从而使UTF8Decode()
在 Delphi 6 中基本上没用(一直到 Delphi 2007 - 它最终在 Delphi 2009 中修复)。
尝试使用 Win32 MultiByteToWideChar()
代替功能,例如:
uses
..., Windows;
function MyUTF8Decode(const s: UTF8String): WideString;
var
Len: Integer;
begin
Len := MultiByteToWideChar(CP_UTF8, 0, PAnsiChar(s), Length(s), nil, 0);
SetLength(Result, Len);
if Len > 0 then
MultiByteToWideChar(CP_UTF8, 0, PAnsiChar(s), Length(s), PWideChar(Result), Len));
end;
var
f : textfile;
s : UTF8String;
w, test : WideString;
begin
while not eof(f) do
begin
readln(f,s);
w := MyUTF8Decode(s);
ANÁLISE8
字符串在 UCS-2 范围内,所以我测试了
UTF8Decode()
在 Delphi 6 中,它解码了
ANÁLISE8
的 UTF-8 编码形式正好。我会得出结论:
UTF8String
变量不包含 ANÁLISE8
的 UTF-8 编码形式以(字节序列 41 4E C3 81 4C 49 53 45 38
)开头,但包含 ASCII 字符串 ANALISE8
相反(字节序列 41 4E 41 4C 49 53 45 38
),它将按原样解码,因为 ASCII 是 UTF-8 的子集。仔细检查您的文件和 Readln()
的输出. WideString
包含 ANÁLISE8
按预期正确,但是您输出/调试它的方式(您没有显示)将其转换为 ANSI,丢失 Á
在转换过程中。 关于delphi - Delphi 6 可以将 UTF-8 葡萄牙语转换为 WideString 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46560453/
我想将虚拟键转换为 WideString。这就是我到目前为止所拥有的...... function VKeytoWideString (Key : Word) : WideString; var W
我有一个在 Windows 中显示气球托盘的函数,它的结构也是这样的: const NIF_INFO = $00000010; NIIF_NONE = $00
我有以下无法编译的代码片段: procedure Frob(const Grob: WideString); var s: WideString; begin s := Gr
我不止一次建议人们使用 WideString 类型的返回值来实现互操作目的。 Accessing Delphi DLL throwing ocasional exception ASP.NET web
我使用此过程将 key 枚举到 Delphi 7 中的 TNTListView (UNICODE) procedure TForm1.TntButton1Click(Sender: TObject);
我有一个文本,需要将其存储在 widestring 变量中。但我的文本是UTF8,而widestring不支持UTF8并将其转换为一些汉字。 WIDESTRING 有 UTF8 版本吗? 我总是使用U
我正在编写一个类,它将宽字符串保存到二进制文件中。我正在使用 Delphi 2005,但该应用程序稍后将移植到 Delphi 2010。我在这里感到非常不确定,有人可以确认一下吗: Delphi 20
该接口(interface)位于_TLB.pas文件 // *********************************************************************/
我正在尝试构建一个(测试)WideString: á (U+00E1 Small Letter Latin A with acute) 但是使用它的分解形式: LATIN SMALL LETTER A
德尔福有一个WrapText功能: function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet; Max
如何将 PAnsiChar 变量转换为 WideString 或 string? 最佳答案 您只需将一个变量分配给另一个变量,然后让 Delphi 编译器为您完成所有转换: var p: PAns
在 C++Builder 中,我编写了以下代码(在 Button1Click 处理程序中),当我在 Debug模式下运行时,我得到“Int3 DbgBreakPoint”(堆栈已损坏?)。 AnsiS
(因为我还没有足够的声望来回答我自己的问题,所以我先把它放在这里。我发布它的时候没有想清楚。对我来说是凌晨 3 点,没有发生让我去别处寻找问题。 我正在创建另一个函数来在 lua 中动态添加一个对象,
我使用delphi 7。 我需要逐行读取一个utf-8文件,每行包含一个单词及其权重(一个数字)因此,我需要读取下一行,然后用分隔符(制表符)分隔行并将其保存在内存中。 所以, 1) Delphi 中
我有一个包含一些数据的 WideString 变量,但是当为字符串分配一些额外的空值时,这些空值或多或少地添加在数据中的随机位置。我现在需要从变量中去除这些空值。如果它是一个字符串,我会检查每个 Ch
我有非常旧的代码(来自 D3): TMyRecord = record Index : Integer; Header : String[70]; Strings : Array[
我有这个代码(我需要将字符串对象添加到 TStringList): var WS: WideString; begin WS := 'allocated string'; SL.AddOb
我很好奇这段代码在 Delphi 2010 中会发生什么: function foo: WideString; var myUnicodeString: UnicodeString; begin
我试图从用 Delphi 编写的 EXE 中接收信息。 EXE 向我传递了一个指向其数据结构之一的指针: Type RecordType = Record St: WideString
我有一种情况需要比较 char* 和 WideString。 如何在 C++ 中将 WideString 转换为 char*? 最佳答案 您可以使用 wcstombs 函数。 size_t wcsto
我是一名优秀的程序员,十分优秀!