Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to UTF-8

Tags:

vbscript

I have a string assigned to variable that's encoded as ansi, for example str = "Пирг"
How can I encode it to UTF-8?

like image 440
user2136786 Avatar asked May 21 '26 09:05

user2136786


1 Answers

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
like image 118
Ansgar Wiechers Avatar answered May 24 '26 18:05

Ansgar Wiechers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!