zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    解决QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'问题
    error while loading shared libraries:libQt5SerialPort.so问题解决
    洛谷P4343 [SHOI2015]自动刷题机
    十一届山东省大学生程序设计竞赛 部分题解
    洛谷P4185 [USACO18JAN]MooTube G 题解
    洛谷P4588 [TJOI2018]数学计算
    洛谷P2085《最小函数值》
    多项式小记
    CF932F 【Escape Through Leaf】
    'ipconfig' 不是内部或外部命令,也不是可运行的程序 或批处理文件。持续思考ing
  • 原文地址:https://www.cnblogs.com/timy/p/1191625.html
Copyright © 2011-2022 走看看