Javascript String ucWords(delimiter)

Description

Javascript String ucWords(delimiter)


/**/*from www . jav a2 s . com*/
 * Upper case all the words of a string split by a delimiter
 * @param delimiter = " " (default is space character)
 * @returns {string}
 */
String.prototype.ucWords = function (delimiter) {
    delimiter = typeof(delimiter) == "undefined" ? /\s+/g : delimiter;
    var words = this.split(delimiter);
    for (var i in words) {
        words[i] = words[i].ucFirst();
    }
    return words.join(delimiter == /\s+/g ? ' ' : delimiter);
}



PreviousNext

Related