Your help has been invaluable. Good luck with it! I'm sorry I didn't catch my errors and omissions earlier.
Copying the data twice once as text to convert the encoding, second time as binary to strip the BOM isn't optimal. However for files less than huge it shouldn't be a problem. Maybe someone else can improve on this or offer some alternative approach? Red Flag This Post Please let us know here why this post is inappropriate.
Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework. Close Box. Log In Come Join Us! Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden. This is just a small optimization though, and all of the flaws would remain. Now this should work great.. Your "adds a space between every character" leads me to suspect just that of your situation.
Instead you might want to pattern your script on something like: Unicode to UTF They simply move the exact Binary image between the Stream and file, with no attempt at any translation or formatting and do not look for or create BOMs.
The CopyTo method also works on Binary bytes, and starts copying bytes from the current Position. This is how we are "deleting" the BOM in the two examples here. You can only truncate from the end of a Stream, you can't trim data from the beginning or the middle of a Stream's contents.
Are we confused yet? I hope this fixes most of the glitches in my original example and also helps address your own situation better. Stream" stream. Open stream. WriteText str stream. SaveToFile filename, 2 stream. Flush stream. Read stream. Improve this answer. Ansgar Wiechers Ansgar Wiechers k 23 23 gold badges silver badges bronze badges. No I don't want to write to file. I'm passing this variable to URL to server which accept only utf-8 encoded strings. WriteText sText ' Close End With end function ' Returns a string that corresponds to the specified byte array, interpreted ' with the specified text encoding, such as "utf-8" or "utfle".
Write byteArray ' Now change the type to text, set the encoding, and output the ' result as text. Close End With End If end function. This should be marked as the best answer, performance-wise. Thank you both. Execute with wscript. Thanks mklement0, but the problem lies on javascript. For some reason, it needs to decode twice. For now it works — Karma Blackshaw. Stream and MSXml2. Why do you re-invent the wheel?
Pure vbscript without any depence of activex is useful. I don't think it's a repeat wheel since there are no other solutions without activex here. So I have some other full example of encoder and decoder: Encoder: ' This script reads jpg picture named SuperPicture.
DOMDocument object and saves ' the resulting data to encoded. Stream" objStream. Open objStream. LoadFromFile "SuperPicture. CreateTextFile "encoded. Write objDocElem. GetFile "encoded. Open ' Get binary value and write to file objStream. Improve this answer. Bob77 Bob77 13k 1 1 gold badge 26 26 silver badges 37 37 bronze badges. Yes, on win7 just look at the string tables of mlang. In English table id is "Japanese Auto-Select ". On XP the string is hard coded in the registry.
How should I do this — zyberjock. Show 4 more comments. WriteText sText. How is using the Stream precisely as intended some kind of "hack" anyway?
And if you want speed there are far better alternatives than the pokey FSO. Bob I don't see any alternatives in your answer. Then why is it's performance abysmal if there was any test case for transcoding? I'm using this script to convert any character set or code page that i'm aware of. Named If objArgumentsNamed. Echo strSyntaxtext WScript.
0コメント