Loading
How to get ASCII value for character?

I am trying to check if a string contains an uppercase and a lowercase character. So need to get the ASCII value for a character. I tried using 'Asc' function but didn't work. How can we can get the ASCII value for a character?


  • Okay, just a screenshot from my InstallScript debugger:

    IS-SampleCharUse.pngIn InstallScript you do not need the "Asc"-function, just assign one character from a string to the "CHAR" data type. Internal it is an int with the ASCII value. You can also assign a CHAR directly to a NUMBER data type.

    regards

    Markus

    Expand Post
    Selected as Best
  • You will not be able to check for the case of characters using just InstallScript. As far as I can tell, all InstallScript string comparison functions are case insensitive. An example is

     

    StrCompare( "A", "a")

     

    which will return 0 (indicates that the two strings are equal). By implication, this means you will not be able to get the correct ASCII value of a character using just InstallScript.

    Using VBScript and regex, you can create a function that will work. Note that VBScript is going away eventually so I wouldn't recommend relying on that and instead write a custom DLL to do the work if you need it. Here is the regex example:

     

    1. prototype BOOL HasUpperAndLowerCase( byval STRING, byref STRING );//---------------------------------------------------------------------------function BOOL HasUpperAndLowerCase( szInput, svError )OBJECTobjRegEx;BOOLbHasUpperAndLowerCase;beginbHasUpperAndLowerCase = FALSE;svError = "";if (szInput = "") thensvError = "input string is empty";elsetry// use VBScript & Regex. NOTE: VBScript support is going away:// https://community.revenera.com/s/article/ka6PL000001RXplYAG objRegEx = CoCreateObject( "VBScript.RegExp" );if IsObject( objRegEx ) then// determine if the input string has upper and lower characters by using a regular expressionobjRegEx.Pattern = "(?=.*[a-z])(?=.*[A-Z])";objRegEx.IgnoreCase = FALSE;bHasUpperAndLowerCase = objRegEx.Test( szInput );else// RegExp is not an objectsvError = "RegExp is not an object";endif;catchsvError = "Error checking case: " + Err.Description;endcatch;if !bHasUpperAndLowerCase thensvError = "Does not have upper and lowercase";endif;endif;return bHasUpperAndLowerCase;end;

     

    usage:

     

    1. bHasUpperAndLowerCase = HasUpperAndLowerCase( szInput, svError );if (bHasUpperAndLowerCase) then MessageBox( "string has Upper and Lowercase characters.", INFORMATION );else MessageBox( svError, SEVERE );endif;

     

     HTH

    Expand Post
  • In which project type do you work (MSI or InstallScript or ...) ?

    regards

    Markus

    • We are working on an installShield project which creates an exe and uses some script written in InstallScript.

      • Okay, just a screenshot from my InstallScript debugger:

        IS-SampleCharUse.pngIn InstallScript you do not need the "Asc"-function, just assign one character from a string to the "CHAR" data type. Internal it is an int with the ASCII value. You can also assign a CHAR directly to a NUMBER data type.

        regards

        Markus

        Expand Post
        Selected as Best

Loading
How to get ASCII value for character?