Giacomo Balli profile picture
Giacomo Balli
Complex decisions. Clear thinking.

I help business owners find new ways to make money with technology, and get the big technology decisions right.
Fluent in business. Grounded in technology. Paid only by you.

Let’s Talk It Through LinkedIn

Building technology products since 2010 · 100+ apps

Capitalize strings

This code sample will allow you to capitalize a string. CSS only allows you to have all lower-case, all upper-case or all words capitalized (not just the first).

String.prototype.capitalize = function () {
    return this.replace(/\S+/g, function (a) {
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
};

Directions:
- Call txt.capitalize() to have the capitalized version.

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:49:16
Back to Blog