js字符串

js字符串:
查詢方法:
字符方法:
charAt;str.charAt(index);返回位置的元素;
charCodeAt;str.charCodeAt(index)返回位置 1 的字符的 Unicode 編碼
fromCharCode;String.fromCharCode(72,69,76,76,79);將根據 Unicode 來輸出 “HELLO”
位置方法:
indexOf:(str.indexOf(“Hello”),返回匹配的起始處。
lastIndexOf:與indexOf沒去別,只是掃描時間反過來。
匹配方法:字符串或正則表達式。
match:str.match(“world”);返回匹配的字符串world,否則返回null。
search;str.search(/W3School/);
replace;str.replace(/Microsoft/,”W3School”)
split;str.split(“,”),用逗號分割將其分割成字符串數組。
操作方法:
拼接方法:
contact;str1.concat(str2)
截取方法:
根據下標截取:
slice;slice(firstIndex,LastIndex),
substring;substring(firstIndex,lastIndexOf);
根據長度截取子串:
substr(index,value);index:位置,value:長度
空格處理:
trim;=trimleft+trimRight;
trimleft;
trimRight;
比較方法:
localCompare;說明比較結果的數字。如果 stringObject 小於 target,則 localeCompare() 返回小於 0 的數。如果 stringObject 大於 target,則該方法返回大於 0 的數。如果兩個字符串相等,或根據本地排序規則沒有區別,該方法返回 0。
編碼方法:
字符串常規編碼與解碼:
ecscape();
unescape();
URI的編碼與解碼:
encodeURI();
decodeURI();
URI組件的編碼與解碼:
encodeURIComponent;
decodeURIComponent;
轉換方法:
大小寫轉換:
toUpperCase();
toLocaleUpperCase();
toLowerCase();
toLocaleLowerCase();
代碼轉換:
var txt=”Hello World!”

    document.write("<p>Big: " + txt.big() + "</p>")
    document.write("<p>Small: " + txt.small() + "</p>")

    document.write("<p>Bold: " + txt.bold() + "</p>")
    document.write("<p>Italic: " + txt.italics() + "</p>")

    document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>")
    document.write("<p>Fixed: " + txt.fixed() + "</p>")
    document.write("<p>Strike: " + txt.strike() + "</p>")

    document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
    document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")

    document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
    document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")

    document.write("<p>Subscript: " + txt.sub() + "</p>")
    document.write("<p>Superscript: " + txt.sup() + "</p>")

    document.write("<p>Link: " + txt.link("http://www.w3school.com.cn") + "</p>")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章