Can we convert Unicode to ASCII in Javascript? charCodeAt () is for Unicode only?

We need to make a small program for our teacher to get the ASCII code of any value in Javascript.

I searched and researched, but there seems to be no way to do this. I just found:

charCodeAt ()

http://www.hacksparrow.com/get-ascii-value-of-character-convert-ascii-to-character-in-javascript.html

Returns a Unicode value, but not ASCII.

I read in this forum that the ASCII value matches the Unicode value for ASCII characters that already have ASCII value:

Are Unicode and Ascii characters the same?

But, it seems, this is not always the case, as, for example, with extended ASCII characters. For example:

var myCaracter = "β”œ";

var n = myCaracter.charCodeAt(0);

document.write (n);

The ASCII value of this character is 195, but the program returns 226 (Unicode value).

, :

ΒΏ ASCII Unicode, ?

!

+4
2

ASCII 7 0 127 ( 0 7F). :

  • ( 0 31, 127)
  • ( 0 9, 48 57)
  • ( 65 90)
  • ( 97 122)
  • .

ASCII Unicode ( "C0 Controls Basic Latin Block" ), UTF-8. ASCII "A" (65 0x41) Unicode "A" (U + 0041).

(β”œ), , ASCII. / , /, ASCII.

8- ASCII, ISO-8859- *. 437 ( MS-DOS), 0xC3 (195). ASCII.

- U + 251C (9500 ), charCodeAt , 226.

, 226, UTF-8, .

+3

, , , , , charCodeAt() ASCII; , , @Rad Lexus.

, , , , , , , , , ASCII 128, charCodeAt(), , .

, , , , , (, , , ), , , , .

, .

:

function validate(text)
{

    var isValid=false;

    var i=0;


    if(text != null && text.length>0 && text !='' )
    {
        isValid=true;

        for (i=0;i<text.length;++i)/*this is not necessary, but I did*/
        {
            if(text.charCodeAt(i)>=128)
            {
                isValid=false;
            }
        }

    }

    return isValid;

}

var isValid=false;

var position=0; 

while(isValid==false)
{
    text=prompt("Enter your text");

    isValid=validate(text);
}
+2

Source: https://habr.com/ru/post/1657553/


All Articles