I have a string assigned to variable that's encoded as ansi, for example str = "Пирг"
How can I encode it to UTF-8?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You mean when writing it to a file? Like this:
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
Edit: If you want the UTF-8 string to go into another variable you could do it like this:
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
文章来源: Convert string to UTF-8