字符串字符JS:1.8,字符串(string)对象(length,indexOf(),lastIndexOf(),replace(),match(),toUpperCase(),toLowerCas

来源:互联网 发布:阴线买入公式源码 编辑:程序博客网 时间:2024/05/01 23:49

上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助。今天在这里和大家一起学习一下字符串字符

    

ylbtech-string:字符串(string)对象

    

  • JavaScript String(字符串)对象 实例
  • length性属
  • indexOf(),lastIndexOf()
  • replace()
  • match()
  • toUpperCase(),toLowCase()

    

JS:1.8.0,JavaScript String(字符串)对象 实例返回顶部

    

算计字符串的度长
如何应用度长性属来算计字符串的度长。
为字符串加添式样
如为何字符串加添式样。
indexOf() 方法
如何应用 indexOf() 来定位字符串中某一个指定的字符次首涌现的位置。
match() 方法
如何应用 match() 来找查字符串中特定的字符,并且如果找到的话,则返回这个字符。
如何替换字符串中的字符 - replace()
如何应用 replace() 方法在字符串顶用某些字符替换另一些字符。

    

JS:1.8.1,length性属 返回顶部
<html><body><script type="text/javascript">var txt="Hello World!"//输出字符串的度长document.write(txt.length)</script></body></html>
JS:1.8.2,indexOf(),lastIndexOf()返回顶部
<html><body><script language="javascript">var txt="Hello world!";// indexOf(),lastIndexOf() 来定位字符串中某一个指定的字符次首涌现的位置//若不存在则返回“-1”document.write(txt+"<br>");document.write("该字符串的度长为:"+txt.length+" <br>");document.write("前从今后找,第一位字符'l'它的索引位置为:"+txt.indexOf('l'+"<br>"));document.write("从后往前查,第一个字符'l'它的索引位置为:"+txt.lastIndexOf('l')+"<br>");</script></body></html>
JS:1.8.3,replace()返回顶部
    每日一道理
青春,有嬉笑声与哭泣声夹杂的年华,青春的少年是蓝天中翱翔的幼鹰,虽然没有完全长大,有些稚气,有些懵懂,脱不开父母的双手却极力想去找寻属于自己的一片天空,为的是一时的激情,为的是一种独自翱翔的感觉!
<html><body><h3>replace(要替换容内,替换成的容内)</h3><script language="javascript">var txt="某某欢喜王帅!";document.write("替换前的容内:"+txt+"<br>");document.write("替换后的容内:"+txt.replace("某某","凤姐"));</script></body></html>
JS:1.8.4,match() 返回顶部
<html><body><script type="text/javascript">var str="Hello world!"document.write(str.match("world") + "<br />")document.write(str.match("World") + "<br />")document.write(str.match("worlld") + "<br />")document.write(str.match("world!"))</script></body></html>
JS:1.8.5,toUpperCase(),toLowCase()返回顶部
<html><body><script language="javascript">var txt="Hello world!";document.write(txt+"<br>");document.write("把全部字符转为大写:"+txt.toUpperCase()+"<br>");document.write("把全部字符转为小写:"+txt.toLowerCase());</script></body></html>