• Equivalent Javascript function

    Author
    Topic
    #429549

    What’s the Javascript equivalent of the VB function Asc() ?. All literature I checked points to fromCharCode() but if I insert an appropriate number as argument, the function won’t return a valid character. Thanks in advance.

    Viewing 1 reply thread
    Author
    Replies
    • #1000663

      fromCharCode is the correct function to use.

      If you enter the following in a web page, the result is abc:

      document.write(String.fromCharCode(97,98,99));

      (Working example)

      • #1000666

        I don’t know JavaScript, but fromCharCode seems to be more or less related to Chr. The function related to Asc is probably charCodeAt:

        function charCodeAtTest(n){
        var str = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; //Initialize variable.
        return str.charCodeAt(n – 1); //Return Unicode value of the n-th character.
        }

    • #1000670

      (Edited by Jezza on 17-Feb-06 10:34. Altered to change tag formatting-Thanks for the tip Hans)

      Hi Raul

      You could use the unescape() method to convert a Hexadecimal value to its ASCII equivalent

      var escapedVal=”%40″;

      var escapedVal=unescape(escapedVal);

      document.write(‘The escapedVal value (‘ + escapedVal + “) “);
      document.write (“evaluates to ” + unescapedVal);

      You can write up the method so that the escapedVal becomes variable you will get a document write

    Viewing 1 reply thread
    Reply To: Equivalent Javascript function

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: