zoukankan      html  css  js  c++  java
  • 字符串

    字符串首字母大写

    //这个我也一直在纠结,英文标题,即使是首字母大写,也未必每一个单词的首字母都是大写的,但是又不知道哪些应该大写,哪些不应该大写
    //ecDo.titleCaseUp('this is a title')
    //"This Is A Title"
    titleCaseUp: function (str, splitType) {
        var _splitType = splitType || /s+/g;
        var strArr = str.split(_splitType),
            result = "", _this = this
        strArr.forEach(function (item) {
            result += _this.changeCase(item, 1) + ' ';
        })
        return this.trim(result, 4)
    }

    字符串找出最长单词

    //ecDo.longestWord('Find the Longest word in a String')
    //result:7
    //ecDo.longestWord('Find|the|Longest|word|in|a|String','|')
    //result:7
    longestWord: function (str, splitType) {
        var _splitType = splitType || /s+/g,
            _max = 0,_item='';
        var strArr = str.split(_splitType);
        strArr.forEach(function (item) {
            if (_max < item.length) {
                _max = item.length
                _item=item;
            }
        })
        return {el:_item,max:_max};
    }
  • 相关阅读:
    CSP游戏 4
    CSP 交通规划
    CSP 地铁修建
    CSP 通信网络
    CSP URL映射
    CSP 权限查询
    CSP Markdown
    CSP JSON 查询
    SQL里的子查询
    SQL里的操作符
  • 原文地址:https://www.cnblogs.com/ly1368489670/p/13915372.html
Copyright © 2011-2022 走看看