Convert string to UTF-8

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!