• String原生类型的扩展


    字符串与String对象
    String.prototype. …
    length:获得字符串长度
    charAt(pos):获得当前位置的字符(串)
    indexOf(str, position):查找字符串
    lastIndexOf(str, position):从后查找字符串
    match(regexp):使用正则表达式检验字符串
    replace(search, replaceValue):替换字符串
    search(regexp):在字符串搜索某个子串
    toUpperCase():将字符串转化为大写
    toLowerCase():将字符串转化为小写

    split(str):分割字符串至数组
    substring(start[, end])
    得到子字符串
    从下标start开始,到下标end-1为止
    如果没有提供end
    slice方法
    与substring方法功能几乎相同
    如果start小于零,则表示倒数第n位(start + length),end亦是如此。

    补充了一些最常用的方法
    String.prototype. …
    endsWith:返回布尔值,表明是否以某字符串结尾
    startsWith:返回布尔值,表明是否以某字符串开始
    trim:返回字符串,去处原字符串首尾空白
    trimEnd:返回字符串,去处原字符串结尾空白
    trimStart:返回字符串,去处原字符串起始空白

    String.format(format, arg1[, arg2[, arg3…]]
    Stirng.format("{0}…", obj, …)
    String.format("{0:format}…", obj, …)
    如果需要保留大括号则使用双括号
    String.format(“{{0}}”, obj, …) = “{0}”
    String.localeFormat(…)
    除format方法的功能之外,提供与当前语言环境相关的字符串转化功能
        <form id="form1" runat="server">
            
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" />
            
            
    <div id="info"></div>
            
    <script language="javascript" type="text/javascript">
                function display(text)
                {
                    document.getElementById(
    "info").innerHTML += (text + "<br />");
                }

                display(String.format(
    "Today is {0}."new Date()));
                display(String.localeFormat(
    "今天是{0:dddd}"new Date()));
            
    </script>
        
    </form>
  • 相关阅读:
    【机器学习】:Xgboost和GBDT的不同与比较
    golang pprof
    终于解决了AMD RYZEN 3970X的散热问题
    2022,你好
    二叉树的遍历 → 不用递归,还能遍历吗
    异或运算的巧用 → 不用额外的变量,如何交换两个变量的值?
    关于 RocketMQ 事务消息的正确打开方式 → 你学废了吗
    单向链表的花式玩法 → 还在玩反转?
    二叉树的简单实战 → 一起温故下二叉树的遍历
    序列化和反序列化
  • 原文地址:https://www.cnblogs.com/timy/p/1191625.html
Copyright © 2020-2023  润新知