当内容混合单字节和双字节时如何使用子字符串/删除字符?
我有一个应用程序,不幸的是在Delphi 6中编写,该应用程序允许用户从输入中提取子字符串 /删除字符。操作员看到tlabel
,这是为了避免直接和不正确的输入。
这适用于英语文本。但是有时,文本是混合内容(ANSI-编码),我设置了charset,并且显示器正常工作而无需修改。
一个微不足道的示例可能是:
月123
十六进制中的字符串是8C 8E | 31 | 32 | 33 | 92 86
(以清晰的字符上拆分字符),
但是一旦修改开始,就会出错。我知道为什么 - 标准的strleft / stright / substring在单个字节上起作用 - 一旦我删除字节,文本就会毫无意义。
我是否必须进行widestring
转换并每次修改某些内容时返回?还是在较旧的Delphi版本中有本机库 /功能来完成我需要的事情?
类似的东西,在伪代码中:
mixedStringLength(content) = 5 // 5 characters visible
mixedStingLeft(content,2) = "月1" // actually the bytes 8C 8E 31
mixedStringDeleteCharsRight(content,1) = "月123" // actually deletes 2 bytes
由于所讨论的字符串在许多其他地方都使用,而且该项目很大,它并不像仅使用TNT库或切换到更新的Delphi版本那样琐碎。
I have an application, which unfortunately is written in Delphi 6, that allows the user to extract substrings / delete characters from input. The operator sees a TLabel
, this is on purpose to avoid direct and incorrect input.
This works fine for English text. But sometimes, the text is mixed content (ANSI-encoded), I set the charset and the display works fine without modification.
One trivial example could be:
月123中
The string in hex is 8C 8E | 31 | 32 | 33 | 92 86
(split on characters for clarity)
But once modification starts, things go wrong. I know why - the standard StrLeft / StrRight / SubString works on single bytes - and once I remove a byte, the text renders meaningless.
Do I have to go through a WideString
conversion and back every time I modify something? Or are there native libraries / functions in older Delphi versions to do what I need?
Something like this, in pseudocode:
mixedStringLength(content) = 5 // 5 characters visible
mixedStingLeft(content,2) = "月1" // actually the bytes 8C 8E 31
mixedStringDeleteCharsRight(content,1) = "月123" // actually deletes 2 bytes
As the string in question is used in many other places, and the project is large, it's not as trivial as just using TNT libraries, or switching over to a newer Delphi version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论