zoukankan      html  css  js  c++  java
  • js怎么截取两个中括号中间的值

    js怎么截取两个中括号中间的值,微秒有时两位有时三位,正则表达式也可以

    [00:02.02],[00:02.342],[00:03.2],[00:03.42],[00:04.02],[00:05.342]

    <body>
        <p id="demo"></p>
        <script>
    
            function getStr(str) {
                if (str == "" || str == null || str == undefined) { // "",null,undefined
                    return "";
                }
    
                var subArr = str.split('');
                var str = "";
                var strTemp = "";
                for (var num = 0; num < subArr.length; num++) {
                    console.log(subArr[num]);
                    strTemp = subArr[num].substr(1, subArr[num].length);
                    strTemp = strTemp.substr(0, subArr[num].length - 2)
                    str += strTemp+",";
                    //console.log(strTemp);
                }
                return str;
            }
    
            document.getElementById("demo").innerHTML = getStr("[00:02.02],[00:02.342],[00:03.2],[00:03.42],[00:04.02],[00:05.342]");
        </script>
    </body>

  • 相关阅读:
    RabbitMQ
    Java 多线程
    Java 多线程
    Java 多线程
    Java 多线程
    Springboot
    SpringBoot
    SpringCloud Config
    Financial
    Hystrix
  • 原文地址:https://www.cnblogs.com/shenbing/p/13776327.html
Copyright © 2011-2022 走看看