How to capitalize all letters in an NSString

user2588945 picture user2588945 · Sep 2, 2013 · Viewed 27.9k times · Source

I'm trying to capitalize all letters in a NSString for a table cell label.

here's my code:

  // cell title and subtitle
cell.nameLabel.text = listingNode.title;
[cell.nameLabel.text uppercaseString];

It doesn't seem to have any effect at all.

thanks for the help.

Answer

Amar picture Amar · Sep 2, 2013

The method uppercaseString returns an uppercased representation of the receiver. Which means you need to collect the returned string and apply that to the label as text.

Try this,

NSString *uppercase = [cell.nameLabel.text uppercaseString];
cell.nameLabel.text =  uppercase;

Hope that helps!