Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capitalize each word of a NSString

I am trying to figure out how to take a given NSString and convert it to camel case. I have seen lots of code samples out there for going back and forth between underscores_ and camel-case, but I am dealing with strings that are capitalized.

So if I had the string: 12345 SAMPLE STREET #12 or 789 N HASKELL STREET, how would I be able to convert those to 12345 Sample Street #12 and 789 N Haskell Street?

Sorry if it's a stupid question, but I'm pretty new to the objective-c / cocoa frameworks world.

like image 391
Henrik Hanssen Avatar asked Sep 25 '10 19:09

Henrik Hanssen


People also ask

How do you capitalize every letter in a string?

Performing the . upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.

What does NSString mean?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

What is the difference between NSString and string?

NSString is a classSwift is interoperatable with Objective-C and converts some Objective-C types to Swift types. Types that can be converted between Obj-C and Swift are known as bridged types. String and NSString are example of such bridged types and hence you can assign NSString to a String variable.

Do I need to release NSString?

If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.


1 Answers

-[NSString capitalizedString]

like image 87
Dave DeLong Avatar answered Sep 24 '22 07:09

Dave DeLong