Joseph Michael Pesch
VP Programming

JavaScript/TypeScript Dotted String to Upper/Lower First Letter

by 16. February 2018 14:56

Take a dotted string (e.g. "someThing.someThingElse.another") and convert first letter of each dotted component to upper or lower case.

    dottedToUpper(str) {
        str = str.replace(/\./g, ' ');
        str = str.replace(/\w\S*/g, function (txt) {
            return txt.charAt(0).toUpperCase() + txt.substr(1);
        });
        return str.replace(/ /g, '.');
    }
    dottedToLower(str) {
        str = str.replace(/\./g, ' ');
        str = str.replace(/\w\S*/g, function (txt) {
            return txt.charAt(0).toLowerCase() + txt.substr(1);
        });
        return str.replace(/ /g, '.');
    }
 

Tags:

Angular | JavaScript | TypeScript

Comments are closed