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>")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章