Jump to content

BinaryToString and Cyrillic chars


Recommended Posts

According to the Help file

BinaryToString converts a binary variant into its ANSI string representation.

What about a binary cyrillic text? I can't manage to convert a unicode text (for example a text in Russian copied to the Clipboard) into its ANSI string representation.

By the way, this is feasible using AutoHotkey which does not have Unicode support (Clipbord Contents --> UTF-8 ---> ANSI string)

Edited by rousni
Link to comment
Share on other sites

According to the Help file

What about a binary cyrillic text? I can't manage to convert a unicode text (for example a text in Russian copied to the Clipboard) into its ANSI string representation.

By the way, this is feasible using AutoHotkey which does not support Unicode (Clipbord Contents --> UTF-8 ---> ANSI string)

don't think there is a possible way

look here and at Au3Lib..

you can convert binary - HEX and binary - string but not cyrillic i think

Edited by c4nm7
Link to comment
Share on other sites

  • Administrators

According to the Help file

What about a binary cyrillic text? I can't manage to convert a unicode text (for example a text in Russian copied to the Clipboard) into its ANSI string representation.

By the way, this is feasible using AutoHotkey which does not support Unicode (Clipbord Contents --> UTF-8 ---> ANSI string)

What exactly are you trying to do? The whole binary/string thing is only usually useful if you are doing tcp/file editing (i.e. not very). If you tell us what you are trying to do there is probably a way to do it.
Link to comment
Share on other sites

I am developing a translation program susceptible to manage efficiently an enormous (distributed) database. ANSI being a more economic format than Unicode, I prefer to store records as ANSI string. So the input is in Unicode, the output is in Unicode too, but the data is stored in ANSI (we need of course information about the language, i.e. the page code). Currently, this is developed using AutoHotkey (http://web.uni-plovdiv.bg/rousni)

Edited by rousni
Link to comment
Share on other sites

  • Administrators

If it's stored in ANSI what's the problem? Conversion will happen automatically between ANSI and unicode. You mention Cryrillic text, so I don't think that's what you actually mean. Maybe you mean that you are storing data as UTF8?

A UDF for a BinaryToStringW is this (might need $a and $b swapping, not sure)

$binary = Binary("0x0041004200430044")  ; ABCD
MsgBox(0, "BinaryToStringW", _BinaryToStringW($binary) )


Func _BinaryToStringW($binary)
    Local $bytes = BinaryLen($binary)
    Local $a, $b
    Local $string

    Local $pos = 1
    While $pos <= $bytes
        $a = Int( BinaryMid($binary, $pos, 1) )
        $b = Int( BinaryMid($binary, $pos+1, 1) )
        $pos += 2
        $a = BitShift($a, -8)
        $a += $b
        $string &= ChrW($a) 
    WEnd

    return $string
EndFunc

If you are messing with UTF8 though I don't think that will help.

Link to comment
Share on other sites

Conversion will happen automatically between ANSI and unicode.

Conversion happens automatically between ANSI and unicode only for the active code page; well, i need french and cyrillic at the same time.

Copy some text in cyrillic in Microsft Word and then try to paste it in some plain text editor (like WinVi, Crimson Editor...) You'll get ????????

(From Windows 95 to Windows Vista)

_BinaryToStringW() is not what I need and in any case this is slow.

I am sorry to say that in a AutoIt forum but I think that AutoHotkey is better in this field with these internal functions:

Transform, OutputVar, Unicode ; Retrieves the clipboard's Unicode text as a UTF-8 string.

Transform, Clipboard, Unicode, %MyUTF_String% ; Places Unicode text onto the clipboard.

Once you have the UTF-8 string, it is easy to convert to ANSI string ( and vice versa)

Edited by rousni
Link to comment
Share on other sites

  • Administrators

Once you have the UTF-8 string, it is easy to convert to ANSI string ( and vice versa)

Ok, but I still don't understand how or why you are using UTF8 or how you are getting it into AutoIt. And I still don't understand what you want me to do about it? Once I understand what you are trying to do I can probably add something to help. But "convert something from the clipboard into UTF8" doesn't sound of any use when all the internal functions don't need any utf8/ansi hacks so I think I'm missing what you are trying to do.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...