Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSString UPPERCASE into Capitalized

I have some strings like NAVJYOT COMPLEX, NEAR A ONE SCHOOL, SUBHASH CHOWK , MEMNAGAR, Ahmedabad, Gujarat, India.

I want to convert them so the first character is uppercase and remaining are lowercase, e.g: Navjyot Complex, Near A One School, Subhash Chowk, Memnagar, Ahmedabad, Gujarat, India. So please help me convert those strings.

Thanks in advance.

like image 907
Nikunj Jadav Avatar asked Sep 23 '11 09:09

Nikunj Jadav


People also ask

What does Nsstring mean?

A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.

What is string capitalize?

string capitalize() in Python Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter, while making all other characters in the string lowercase letters.

How do you capitalize a string in Swift?

The uppercased() method converts all lowercase characters in a string into uppercase characters.


2 Answers

nsstring has the following method

capitalizedString

it returns:

"A string with the first character from each word in the receiver changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values."

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

like image 165
J_S Avatar answered Oct 07 '22 01:10

J_S


use This one

NSString *str1 = @"ron";
NSString *str = [str1 capitalizedString];
like image 32
Rahul Juyal Avatar answered Oct 07 '22 02:10

Rahul Juyal