我有一个分配给编码为 ansi 的变量的字符串,例如str = "Пирг"
如何将其编码为 UTF-8?
问问题
21646 次
1 回答
2
你的意思是当它写入文件时?像这样:
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.Position = 0
stream.Charset = "utf-8"
stream.WriteText str
stream.SaveToFile filename, 2
stream.Close
编辑:如果您希望 UTF-8 字符串进入另一个变量,您可以这样做:
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.Position = 0
stream.Charset = "utf-8"
stream.WriteText str
stream.Flush
stream.Position = 0
stream.Type = 1 'binary
stream.Read(3) 'skip BOM
utfStr = stream.Read
stream.Close
于 2013-03-05T17:29:58.287 回答