[MTR04] W2 D8 String 類型的內建函式


Posted by Christy on 2020-06-27

看影片:String 類型的內建函式

String 類型的內建函式

  • toLowerCase
var a = 'ABC'.toLowerCase()
console.log(a)  就會印出 'abc'
  • toUpperCase
var a = 'abc'.toUpperCase()
console.log(a)  就會印出 'ABC'
  • ASCII Code: 字串存在電腦裡面,真正存的東西,是一個對應的數字
  • 用 charCodeAt 可以得到 ASCII Code 的那個數字
var a = 'A'
var aCode = a.charCodeAt(0)  //-> 代表變數位置 0, 1, 2 ...
console.log(aCode)  //就會印出 65,也就是說大寫 A = 65
  • from charCode,反過來;從 ASCII Code 的數字推回英文字母
var str = String.fromCharCode(65) //注意大小寫
console.log(str)  //就會印出 A
  • 小寫轉大寫
var a = 'g'
var aCode = a.charCodeAt(0)
var str = String.fromCharCode(aCode - 32) 
console.log(str)
//就會印出大寫 G
//A = 65, a = 97; 97 - 65 = 32,意即 -32 變大寫, +32 變小寫
//英文大小寫字母,是連續不中斷,且有相關連的

參考資料:
String










Related Posts

使用 Object Recognition Kitchen 的 Linemod 演算法辨識物體

使用 Object Recognition Kitchen 的 Linemod 演算法辨識物體

SSTI lab

SSTI lab

[Go] How to speed up debug on VS Code?

[Go] How to speed up debug on VS Code?


Comments