为了账号安全,请及时绑定邮箱和手机立即绑定

字符串相关处理

  1.  去除字符串中的所有空格:

    str=str.replace(/\s*/g,"");

  2. 判断字符串中是否含中文:

    if(/[\u4E00-\u9FA5]+/.test(str))

  3. 字符串首字母大写:

    str=str.substring(0, 1).toUpperCase() + str.substring(1);

  4. 将两个或多个字符的文本组合起来,返回一个新的字符串。
    var a = "hello";
    var b = ",world";
    var c = a.concat(b);

  5. 返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。

    str="hello";

    var index=str.indexOf("e");     // index=1

  6. 替换字符串中的指定字符

    str="hello"

    str=str.replace(/l/g,'m');      //str="hemmo"

  7. 通过标识截取特定字符串

    str="hello world,66666"

    str2=str.split(",");   //以逗号分割

    得到str2=["hello world","66666"]

  8. 截取两个标识之间的内容

    var relink="http://www.baidu.com/video/10255123.html";

    var re=relink.substring(relink.lastIndexOf('/')+1,relink.lastIndexOf('.'));

    console.log(re);     //102555123

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消