为什么使用 ADODB.Stream 和 ASCII 字符集特殊字符 ä都转换成a?
我在尝试将 vb6 中的某些变量的内容输出到文本文件中时遇到问题。问题是,当扩展 ASCII 中的特殊字符显示为 ä、ü、á 时,它会在输出中转换为匹配的基本 ASCII 字符,如 a、u、a。
我尝试像 UTF-8 一样导出它,然后正确显示字符,但我需要输出为 ASCII。另外,对我来说看起来很奇怪的是文件名通常可以包含这个字符(ä,ü,á...)而无需替换。
这是因为“ASCII”字符集只是基本字符集而不是扩展字符集吗?也许是因为 Windows 中配置的代码页?我尝试过其中的几个(德语、英语),结果相同。
这是我正在使用的代码:
Set fileStream = New ADODB.Stream
If Not fileStream Is Nothing Then
inputString = textPreAppend + inputString
fileStream.charSet = "ASCII"
fileStream.Open
fileStream.WriteText inputString
fileStream.Flush
fileStream.SaveToFile fileName, adSaveCreateOverWrite
fileStream.Flush
fileStream.Close
End If
Set fileStream = Nothing
提前致谢!
I'm having a problem trying to output the content of some variables in vb6 into a text file. The thing is that when a special character from extended ASCII appears as ä, ü, á it is transformed in the output to the matching basic ASCII char like a, u, a.
I've tried to export it like UTF-8 and then the character is shown correctly, but I need the output to be ASCII. Also, looks strange for me that the filename can normally contain this chars (ä, ü, á...) without sustitution.
Can this be because "ASCII" charset is just the basic and not the extended? Maybe because of the CodePages configured in Windows? I've tried with a couple of them (German, English) with the same result.
This is the code I'm using:
Set fileStream = New ADODB.Stream
If Not fileStream Is Nothing Then
inputString = textPreAppend + inputString
fileStream.charSet = "ASCII"
fileStream.Open
fileStream.WriteText inputString
fileStream.Flush
fileStream.SaveToFile fileName, adSaveCreateOverWrite
fileStream.Flush
fileStream.Close
End If
Set fileStream = Nothing
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PRB:ADO 流对象的字符集属性可能需要 Microsoft Internet Explorer 升级 和 字符集属性 (ADO) 建议 ADO CharSet 值是
HKEY_CLASSES_ROOT\MIME\Database\Charset
下列出的值,但这显然不是全部。例如,值“ascii”和“us-ascii”都作为“iso-8859-1”的别名列出,但是在我的语言环境设置为美国英语的情况下运行,它们的行为就像 7 位 ASCII MIME 类型。他们几乎不得不这样做,因为无论如何都没有提供任何其他内容来请求 7 位 ASCII 编码。
这会产生您似乎想要的结果:
输出:
我们必须假设要求“ascii”(值全部小写,但显然不区分大小写)意味着 7 位 ASCII,可能是本地化的。
使用 UTF-8 不是一个好主意,除非您想要 UTF-8。虽然许多 *nix 系统假装没有区别,但 Stream 会写入 BOM,当然那些扩展(非 ASCII)字符是多字节编码的。
Both PRB: Charset Property of ADO Stream Object May Require Microsoft Internet Explorer Upgrade and Charset Property (ADO) suggest that ADO CharSet values are those listed under
HKEY_CLASSES_ROOT\MIME\Database\Charset
but that clearly is not the entire story.For example both values "ascii" and "us-ascii" are listed there as aliases of "iso-8859-1" however running with my locale set to U.S. English they act like a 7-bit ASCII MIME type. They'd almost have to, since there is nothing else provided for requesting 7-bit ASCII encoding anyway.
This produces the result you seem to want:
Output:
We have to assume that asking for "ascii" (the values are all lowercased though clearly are not case-sensitive) means 7-bit ASCII, perhaps localized.
Using UTF-8 is a bad idea unless you want UTF-8. While a lot of *nix systems pretend there is no difference, the Stream will write a BOM and of course those extended (non-ASCII) characters are multibyte encoded.
为什么你不能做如下的事情呢?这对我来说没问题:
Why can't you just do something like the following? This works ok for me: