欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您的位置:DIVCSS5首页 > HTML >
字符串(String)
 
字符串(String)使用长度属性length来计算字符串的长度:
 
实例
var txt="Hello World!";
document.write(txt.length);
 
var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(txt.length);
 
 
在字符串中查找字符串
 
字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置:
 
实例
var str="Hello world, welcome to the universe.";
var n=str.indexOf("welcome");
 
 
如果没找到对应的字符函数返回-1
 
lastIndexOf() 方法在字符串末尾开始查找字符串出现的位置。
 
内容匹配
 
match()函数用来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。
 
实例
 
var str="Hello world!";
document.write(str.match("world") + "<br>");
document.write(str.match("World") + "<br>");
document.write(str.match("world!"));

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64886.shtml

如对文章有任何疑问请提交到DIV CSS论坛,或有任何网页制作CSS问题立即到CSS论坛发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。
CSS教程文章修订日期:2018-08-14 17:37 原创:DIVCSS5
本文www.divcss5.com DIVCSS5版权所有。