Modify

Opened 16 years ago

Closed 16 years ago

#894 closed Bug (No Bug)

StringToASCIIArray() with UTF-8 encoding gives wrong result

Reported by: O'Ehby Owned by:
Milestone: Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: StringToASCIIArray UTF-8 Cc:

Description

StringToASCIIArray() with UTF-8 encoding gives wrong result

Local $str = BinaryToString(Binary(0xB2CEB1CE), 4)		; converting 2 utf-8 symbols (CE B1 - alpha, CE B2 - beta) to string
MsgBox(1, "utf-8 string", $str)					; test if symbols are properly converted
Local $arr = StringToASCIIArray($str, 0, Default, 2)		; convert string to array of utf-8 charcodes

$str = "["
Local $i

For $i = 0 To UBound($arr) - 1
	$str &= StringFormat("0x%X, ", $arr[$i])		; get array content. expecting [0x0000B1CE, 0x0000B2CE], right?
Next
MsgBox(1, "utf-8 array", StringTrimRight($str, 2) & "]")	; see [0xFFFFFFB1, 0xFFFFFFCE]

Environment = 3.3.0.0 under WIN_XP/Service Pack 2 X86

Attachments (0)

Change History (1)

comment:1 Changed 16 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

This line of code:

Local $str = BinaryToString(Binary(0xB2CEB1CE), 4)

After that call you are done with UTF-8. The variable $str now UNICODE. The problem is you are mangling the data in the call to StringToASCIIArray() because you lie to it and tell it the string is UTF-8 when in reality no it's not. However, it does what you tell it to and returns garbage as a result. I hope I don't need to explain what the fix is.

This is not a bug.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.