標籤:eof rom 換行 空格 arch 方法 from search 執行個體
String是一串Unicode字元序列。String全域對象是用來構造字串對象或者字元序列的建構函式
文法
1. 字串的字面量文法,在ES6標準中,稱為模板字面量。具體可以參考TypeScript
2. String建構函式 String(thing) / new String(thing)
逸出字元
\0 \‘ \" \\ \n \r \t \v \b \f \uXXXX
長字串
兩種方法:
1. 使用+運算子將多個字串串連
2. 每行末尾使用反斜線 \ 以指示字串會在下一行繼續。確保反斜線後面沒有空格或者任何除分行符號以外的字元或者縮排。
字串對象的方法及應用情境
1. 從字串中擷取單個字元
charAt
數組索引方式 [ ]
2. 字串比較
> < >= <=
localeCompare()
3. 基底字元串和字串對象的區別
字串字面量和直接通過String方法的字串都是基底字元串,JS會自動將基底字元串轉換為字串對象。只有字串對象才能使用String對象的方法。
String屬性
String.prototype.constructor
String.prototype.length
String方法
靜態方法: String.fromCharCode()
執行個體方法: String.prototype.charAt()
String.prototype.charCodeAt()
String.prototype.codePointAt()
String.prototype.concat()
String.prototype.indexOf()
String.prototype.lastIndexOf()
String.prototype.localeCompare()
String.prototype.match()
String.prototype.replace()
String.prototype.search()
String.prototype.split()
String.prototype.substr()
String.prototype.substring()
String.prototype.toLocaleLowerCase()
String.prototype.toLocaleUpperCase()
String.prototype.toLowerCase()
String.prototype.toString()
String.prototype.toUpperCase()
String.prototype.trim()
String.prototype.valueOf()
[JavaScript文法學習]全面介紹String