JavaScript String 对象

/* charAt() 返回指定索引位置的字符
var str=“helloworld”;
var newArr = str.charAt(1);
alert(newArr);*/
/charCodeAt() 返回在指定的位置的字符的 Unicode 编码。
var str = “helloworld”;
var newArr = str.charCodeAt(3);
alert(newArr);
/
/concat() 连接两个或更多字符串,并返回新的字符串。
var str = “helloworld”;
var newArr = str.concat(110,888);
alert(newArr);
/
/*fromCharCode() 将 Unicode 编码转为字符。

   var newArr = String.fromCharCode(98,97,96,95);
   alert(newArr);*/

/indexOf() 返回某个指定的字符串值在字符串中首次出现的位置。
var str = “helloworld”;
var newArr = str.indexOf(“o”);
alert(newArr);
/
/lastIndexOf() 从后向前搜索字符串,并从起始位置(0)开始计算返回字符串最后出现的位置。
var str = “helloworld”;
var newArr = str.lastIndexOf(“o”);
alert(newArr);
/
/match() 查找找到一个或多个正则表达式的匹配。
var str = “hellowhellhello”;
var newArr = str.match(/lo/g);
alert(newArr);
/
/* repeat() 复制字符串指定次数,并将它们连接在一起返回。

  var str = "hellowhellhello";
   var newArr = str.repeat(3);
   alert(newArr);*/

/replace() 在字符串中查找匹配的子串, 并替换与正则表达式匹配的子串。
var str = “hellowhellhello”;
var newArr = str.replace(“hello”,“ppppp”);
alert(newArr);

/search() 查找与正则表达式相匹配的值。
var str = “hellowhellhello”;
var newArr = str.search(/ll/);
alert(newArr);
/
/slice() 提取字符串的片断,并在新的字符串中返回被提取的部分。
var str = “hellowhellhello”;
var newArr = str.slice(1,3);
alert(newArr);
/

   /*split()	把字符串分割为字符串数组。
   var str = "hellowhellhello";
   var newArr = str.split("");
   alert(newArr);*/

/substr() 从起始索引号提取字符串中指定数目的字符。
var str = “hellowhellhello”;
var newArr = str.substr(1,4);
alert(newArr);
/
/substring() 提取字符串中两个指定的索引号之间的字符。
var str = “hellowhellhello”;
var newArr = str.substr(2,4);
alert(newArr);
/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值