Jump to content

ASC wrong number


Go to solution Solved by Danp2,

Recommended Posts

Hi

i want the Asc Number of "ć", which is 262.

But with Asc("ć") i get 99 instead, which is the number for "c".

It's used in a script, which checks if a string contents any characters above 255.

Thanks for assistance.

 

cheers mike

Link to comment
Share on other sites

The Unicode codepoint of ć is 0x107, that is decimal 263, not 262.

ConsoleWrite(AscW("ć") & @LF)

 

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)

Link to comment
Share on other sites

hi again,

is there an existing autoit function
or atleast a faster way for this:

$bSuccess = True

For $i = 1 To StringLen($sString)
    If ASCW(StringMid($sString, $i, 1)) > 255 Then
        $bSuccess = False

        ExitLoop
    EndIf
Next

Return $bSuccess

in fact "StringIsASCII($sString)" works much faster.

thanks for advice

cheers mike

Link to comment
Share on other sites

; sample Unicode strings in AutoIt encoding (UCS2)
Local $a = [ _
    "All lower ASCII here!", _
    "Some characters ¼½¾ÀÁÇÖæÿ in upper ANSI 1252", _
    "Some characters > 0xFF: Μεγάλο πρόβλημα" _
]

For $s In $a
    ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "^[\x00-\x7F]*$") ? "" : "NOT ") & "only lower ASCII" & @LF)
    ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "[\x80-\xFF]") ? "some" : "NO ") & "upper ASCII" & @LF)
    ConsoleWrite('"' & $s & '"' & " contains " & (StringRegExp($s, "[\x{100}-\x{FFFF}]") ? "" : "NO ") & "characters > 0x100" & @LF)
Next

 

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)

Link to comment
Share on other sites

hi jchd,

thanks lot for the regex.

I modified my function with them:

Func StringIsANSI($sString)
    Local $bSuccess, $iLen

    $bSuccess = False

    $iLen = StringLen($sString)

    If $iLen > 0 Then
        If StringRegExp($sString, "[\x00-\x7F]") Or StringRegExp($sString, "[\x80-\xFF]") Then
            $bSuccess = True
        EndIf

        If StringRegExp($sString, "[\x{100}-\x{FFFF}]") Then
            $bSuccess = False
        EndIf
    EndIf

    Return $bSuccess
EndFunc   ;==>StringIsANSI

This works now exellent like in notepad.

If a string passes this function with success it can be saved with notepad as ANSI.

If the string includes for example "Mišel Matičević",
it does not pass the function with success and cannot be saved with notepad as ANSI.

Thanks lot again.

Cheers mike

Link to comment
Share on other sites

@mike1950r You should be able to do it with a single regex --

Func StringIsANSI($sString)
    Local $bSuccess, $iLen

    $bSuccess = True

    $iLen = StringLen($sString)

    If $iLen And StringRegEx($sString, "[^\x00-\xFF]") Then
        $bSuccess = False
    EndIf

    Return $bSuccess    
EndFunc   ;==>StringIsANSI

This returns True for an empty string, but otherwise it should match your earlier code.

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...