Jump to content
Sign in to follow this  

How to convert a string into UTF16

Recommended Posts


Hi there, maybe someone can help?

I'm trying to convert a string into the UTF16 format.

In php I can use a function like this:

function Str2Utf16($string) {
$string = iconv("ISO-8859-1", "UTF-16", $string);
return substr($string, 2, strlen($string)-2);

In VBA there seems to be no need to convert the string - but AutoIt (even though I'm using v. seems to handle the string as UTF8, just like php.

Why do I need this?

I'm trying to send a http-Request to the AVM Fritzbox 7270 in order to log in to the webinterface. Therefore I need to construct a string in the UTF-16-LE format (without BOM and final zero-bytes). Details: http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf

I already tried something like this: (found within another post in this forum: http://www.autoitscript.com/forum/index.php?showtopic=92061&st=0&p=662436&hl=utf16&fromsearch=1&), but this doesen't work for me >_<

; string conversion: UTF-8 --> UTF-16
Func _Utf8ToUtf16($Utf8String)
Local $struct = _WinAPI_MultiByteToWideChar($Utf8String, 65001)

Thanx for any replies an help


Edited by trainer

Share this post

Link to post
Share on other sites

Taken from help_file:

StringToASCIIArray( "string", [ start [, end [, encoding ] ] ] )

encoding [optional] The returned array will contain values in the specified character set:

0 - UTF-16 (Default)

1 - ANSI

2 - UTF-8

#include <Array.au3>    ; For _ArrayDisplay()

Local $a = StringToASCIIArray("abc")


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.