Home AMX User Forum NetLinx Studio

Unicode -> ASCII

Anyone written a Unicode to ASCII function? I'm thinking of writing one myself, because I need to store something a module sends my touchpanel in a variable, but it's being sent to the touchpanel in a ^UNI- command. e.g.
Line      3 :: Command To [33033:1:1]-[^UNI-116,0,005200450050004500410054007C0041004C004C] - 11:54:16
Basically I am going to read 4 characters at a time and use hextoi followed by type_cast to get a character, and add it to my string. But there is probably a better way.

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    If you do a search for ?Unicode? in Netlinx keywords help there are a bunch of Unicode functions that are available such as:

    _WC
    CH_TO_WC
    WC_COMPARE_STRING
    WC_CONCAT_STRING
    WC_DECODE
    WC_ENCODE
    WC_FILE_CLOSE
    WC_FILE_OPEN
    WC_FILE_READ
    WC_FILE_READ_LINE
    WC_FILE_WRITE
    WC_FILE_WRITE_LINE
    WC_FIND_STRING
    WC_GET_BUFFER_CHAR
    WC_GET_BUFFER_STRING
    WC_LEFT_STRING
    WC_LENGTH_STRING
    WC_LOWER_STRING
    WC_MAX_LENGTH_STRING
    WC_MID_STRING
    WC_REMOVE_STRING
    WC_RIGHT_STRING
    WC_SET_LENGTH_STRING
    WC_TO_CH
    WC_TP_ENCODE
    WC_UPPER_STRING

    Maybe one of the above may be of some help?
    mpullin wrote:
    Anyone written a Unicode to ASCII function? I'm thinking of writing one myself, because I need to store something a module sends my touchpanel in a variable, but it's being sent to the touchpanel in a ^UNI- command. e.g.
    Line      3 :: Command To [33033:1:1]-[^UNI-116,0,005200450050004500410054007C0041004C004C] - 11:54:16
    
    Basically I am going to read 4 characters at a time and use hextoi followed by type_cast to get a character, and add it to my string. But there is probably a better way.
  • mpullinmpullin Posts: 949
    Also can't find WC_TO_CH. My compiler is v.2.4.0.1. I'll see if I can do it after I do a WebUpdate and get the latest NS.

    Oh... you have to #INCLUDE 'UnicodeLib.axi'


    This code just gets me a bunch of question marks... I'm starting to get frustrated with this Unicode thing
    DEFINE_FUNCTION CHAR UNI2ASCII (CHAR c[]){
        return TYPE_CAST(WC_TO_CH(_WC(c)))
    }
    
  • Joe HebertJoe Hebert Posts: 2,159
    There is a checkbox under the ?Netlinx Compiler? tab under Preferences that says ?Enable_WC Preprocessor (Unicode)? that needs to be checked if you want to use the library, or so I assume. I've never used any of the functions myself.
    mpullin wrote:
    Also can't find WC_TO_CH. My compiler is v.2.4.0.1. I'll see if I can do it after I do a WebUpdate and get the latest NS.

    Oh... you have to #INCLUDE 'UnicodeLib.axi'


    This code just gets me a bunch of question marks... I'm starting to get frustrated with this Unicode thing
    DEFINE_FUNCTION CHAR UNI2ASCII (CHAR c[]){
        return TYPE_CAST(WC_TO_CH(_WC(c)))
    }
    
  • mpullinmpullin Posts: 949
    Finally solved it this morning. This function does the trick:
    DEFINE_FUNCTION CHAR[1] UNI2ASCII (CHAR c[]){
        // passed '0042' will return 'B'
        STACK_VAR INTEGER yy
        yy = hextoi(RIGHT_STRING(c,2))
        RETURN "yy"
    }
    
Sign In or Register to comment.