xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub! convert number or string to ASCII in js

ASCII dictionary generator

  // const dict = `abcdefghijklmnopqrstuvwxyz`;

  const begin = `a`.charCodeAt();
  const end = `z`.charCodeAt();
  let dict = ``;
  for (let i = begin; i < end; i++) {
    dict += String.fromCodePoint(i);
  }
  log(`dict =`, dict);
  // dict = abcdefghijklmnopqrstuvwxy

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
convert number or string to ASCII in js

String.fromCodePoint

number or string to ASCII

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint


String.fromCodePoint(65);
//"A"
String.fromCodePoint(`65`);
//"A"

String.fromCharCode

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode

String.fromCharCode(65)
// "A"
String.fromCharCode(`65`);
// "A"

``. codePointAt

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt


const icons = 'ab';

console.log(icons.codePointAt());
console.log(icons.codePointAt(0));
console.log(icons.codePointAt(1));
// 97
// 97
// 98

``.charCodeAt

ASCII character to number

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt


`a`.charCodeAt();
  // 97
 `z`.charCodeAt();
  // 122

`A`.charCodeAt();
  // 65
`Z`.charCodeAt();
  // 90

ASCII Table

printable ASCII characters

xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
convert number or string to ASCII in js

refs

https://leetcode.com/problems/valid-palindrome/

https://leetcode.com/submissions/detail/368171836/

http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm


xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
convert number or string to ASCII in js

©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!