JS

将字符串中的每个单词大写

function capitalizeWords(str)
    {
        return str.replace(/wS*/g, function(txt){return txt.substr(0).toUpperCase();});
    }

从字符串中提取指定数量的字符。

truncate_string = function (str1, length) {
    if ((str1.constructor === String) && (length>0)) {
        return str1.slice(0, length);
    }
};

本文来自博客园,作者:咸瑜,转载请注明原文链接:https://www.cnblogs.com/bi-hu/p/14861791.html

原文地址:https://www.cnblogs.com/bi-hu/p/14861791.html