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>
  • 相关阅读:
    解压tar.gz文件报错gzip: stdin: not in gzip format解决方法
    通过 HTTP 头进行 SQL 注入(转)
    Android涉及到的设计模式(转)
    初探Java8中的HashMap(转)
    substance的使用示例(转)
    大数据量下高并发同步的讲解(不看,保证你后悔)(转)
    HDU 4812 D Tree 树分区+逆+hash新位置
    在weblogic11g发布该项目时遇到错误(不支持web-app_3_0)
    highchart几个图表马金摘要
    android 使用 service 实现音乐
  • 原文地址:https://www.cnblogs.com/timy/p/1191625.html
Copyright © 2011-2022 走看看