Jump to content
Sign in to follow this  

unicode and ascii

Recommended Posts

i trying to write script that correct ALT+SHIFT mistake (when u forget to press ALT+SHIFT and write sentence in English chars instead of Hebrew)

the script take the clipboard (i don't know how to take the highlight text - if some one know please say)

and for each char: replace the char with the correct char

the problem:

some chars in Hebrew have the same ASCII value:


so the script can't detect the right char

of course that they don't have the same Unicode value

how can i fix the problem? (how autoit can recognize chars with the same ASCII but different Unicode)

thank you


Share this post

Link to post
Share on other sites

I think you misunderstand what you are seeing. The text is either ASCII or Unicode, not a mix of both. UTF-8 was designed for backwards compatibility with ASCII, but that only applies to code points 0 thru 0x7F. It doesn't mean anything to pass a Unicode character to the Asc() function. It is not meant to "translate" like that.

To represent Hebrew Tsadi (צ) actually requires two UTF-8 bytes: 0x05E6

If you want to see the code in AutoIt, it would look like this. Note the use of AscW():

$iAscii = Asc("צ")
$iUTF8 = AscW("צ")
ConsoleWrite("Tsadi:  $iAscii = 0x" & Hex($iAscii) & "(invalid)  --  $iUTF8 = 0x" & Hex($iUTF8) & @LF)

$iAscii = Asc("Y")
$iUTF8 = AscW("Y")
ConsoleWrite("Y:  $iAscii = 0x" & Hex($iAscii) & "  --  $iUTF8 = 0x" & Hex($iUTF8) & @LF)


Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

i will try again

here is the script:

$flag = True
$j = 0
$temp = ""
$clip = ClipGet()
$len = StringLen($clip)
$str = ""
$_str = "/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.qwertyuiop[]asdfghjkl;'zxcvbnm,./"
for $i = 1 to $len step +1
    $flag = True
    $j = 0
    $temp = StringMid($clip,$i,1)
    While $j < $66 And $flag
        $j = $j +1
        If $temp = StringMid($_str,$j,1) Then
            $temp = StringMid($_str,Mod($j+33,66),1)
            $flag = False
    $str = $str & $temp 

_str is string that i create such _str[x] is the hebrew char and _str[x] is the english char in the same key of _str[x]

the problem that if temp = "צ"

($temp ="צ")=true

but ($temp ="ץ")=true too

i don't know why

here you can see that Tsadi have two appearance final and non-final

the ASCII of them is equal

but the Unicode is different


$iAscii = Asc("צ")
$iUTF8 = AscW("צ")
ConsoleWrite("Tsadi:  $iAscii = 0x" & Hex($iAscii) & "(invalid)  --  $iUTF8 = 0x" & Hex($iUTF8) & @LF)

$iAscii = Asc("ץ")
$iUTF8 = AscW("ץ")
ConsoleWrite("final Tsadi:  $iAscii = 0x" & Hex($iAscii) & "  --  $iUTF8 = 0x" & Hex($iUTF8) & @LF)


>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\desktop\temp.au3"

Tsadi: $iAscii = 0x0000003F(invalid) -- $iUTF8 = 0x000005E6

final Tsadi: $iAscii = 0x0000003F -- $iUTF8 = 0x000005E5

>Exit code: 0 Time: 0.219

i hope that i explain the problem clear enough

thank you


Edited by hellfire03

Share this post

Link to post
Share on other sites

ANSI codepages are evil!

Switch everything to Unicode and you'll see the light!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...