gpt4 book ai didi

delphi - Delphi 中泰语 UTF-8 编码字符串的实际长度

转载 作者:行者123 更新时间:2023-12-04 13:46:26 25 4
gpt4 key购买 nike

泰语是一种非常特殊的语言。您可以像其他任何语言一样在辅音之后写元音(总共 32 个),或者在它的前面,或者在它的顶部,或者在它的底部(好吧,只有短和长的“u”音可以在底部,但无论如何......)。

此外,还有其他修饰符(4 音标、ga-ran、mai-tai-ku 和其他修饰符)可以放在已经存在的元音之上!

例如:

 ที่ดีที่สุด (the best)

如您所见,如果我尝试使用等宽字体打印它,“实际长度”将为 5 个字符,但所有 UTF-8 strlen 例程都返回 11 个字符——这是完全正确的,但我需要知道在等宽打印时字符串将在屏幕/打印机上使用的“实际空间”。

当然,一个简单的解决方案是列出可以出现在单词顶部或底部的所有特殊字符,并将它们从总数中删除。

由于我不确定是否可以找到所有特殊字符,是否已经有任何语言的例程,以便我可以在 Delphi 中进行翻译?

谢谢

最佳答案

在 C++ 中:

    /*---------------------------------------------------------------------------*/
/* thai_tcslen */
/*---------------------------------------------------------------------------*/
short thai_tcslen(_TCHAR *buff)
{
short bufpos;
short normal_length;
short thai_length;

thai_length=0;
normal_length = _tcslen(buff);
for (bufpos = 0; bufpos < normal_length; bufpos++) {
if ( *(buff+bufpos) != _T('Ñ')/*mai han na kaad*//*-047*/
&& *(buff+bufpos) != _T('Ô')/*sara ee *//*-044*/
&& *(buff+bufpos) != _T('Õ')/*sara eeeee *//*-043*/
&& *(buff+bufpos) != _T('Ö')/*sara uu *//*-042*/
&& *(buff+bufpos) != _T('×')/*sara uuuuu *//*-041*/
&& *(buff+bufpos) != _T('Ø')/*sara oo *//*-040*/
&& *(buff+bufpos) != _T('Ù')/*sara ooooo *//*-039*/
&& *(buff+bufpos) != _T('ç')/*mai tai khoo *//*-025*/
&& *(buff+bufpos) != _T('è')/*mai aek *//*-024*/
&& *(buff+bufpos) != _T('é')/*mai toe *//*-023*/
&& *(buff+bufpos) != _T('ê')/*mai cha ta wah *//*-022*/
&& *(buff+bufpos) != _T('ë')/*mai tree *//*-021*/
&& *(buff+bufpos) != _T('ì')/*ka ran *//*-020*/
) {
thai_length++;
}
}

return(thai_length);
} /* thai_tcslen */
在 VB6 中:
    Public Function ThaiStringLength(ByRef ThaiString As String) As Long
Dim b As String, noLengthChars(13) As Byte
b = ThaiString

noLengthChars(0) = 209
noLengthChars(1) = 212
noLengthChars(2) = 213
noLengthChars(3) = 214
noLengthChars(4) = 215
noLengthChars(5) = 216
noLengthChars(6) = 217
noLengthChars(7) = 231
noLengthChars(8) = 232
noLengthChars(9) = 233
noLengthChars(10) = 234
noLengthChars(11) = 235
noLengthChars(12) = 236

Dim o As Long
For o = 0 To 12
If InStr(b, Chr(noLengthChars(o))) > 0 Then
b = Replace(b, Chr(noLengthChars(o)), "")
End If
Next
ThaiStringLength = Len(b)
End Function

关于delphi - Delphi 中泰语 UTF-8 编码字符串的实际长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46578142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com