Changes

Working with String Objects in Objective-C

1,553 bytes added, 20:43, 3 November 2009
Converting to Upper or Lower Case
== Converting to Upper or Lower Case ==
 
The Foundation NSString classes provide a variety of methods for modifying different aspects of case within a string. Note that each of these methods returns a new string object reflecting the change, leaving the original string object unchanged.
 
* '''capitalizedString'''
 
Returns a copy of the specified string with the first letter of each word capitalized and all other characters in lower case:
 
<pre>
NSString *string1 = @"The quicK brOwn fox jumpeD";
NSString *string2;
 
string2 = [string1 capitalizedString];
 
</pre>
 
The above code will return a string object containing the string "The Quick Brown Fox Jumped" and assign it to the string2 variable. The string object referenced by string1 remains unmodified.
 
* '''lowercaseString'''
 
Returns a copy of the specified string with all characters in lower case:
 
<pre>
NSString *string1 = @"The quicK brOwn fox jumpeD";
NSString *string2;
 
string2 = [string1 lowercaseString];
</pre>
 
The above code will return a string object containing the string "the quick brown fox jumped" and assign it to the string2 variable. The string object referenced by string1 remains unmodified.
 
* '''uppercaseString'''
 
Returns a copy of the specified string with all characters in upper case:
 
<pre>
NSString *string1 = @"The quicK brOwn fox jumpeD";
NSString *string2;
 
string2 = [string1 uppercaseString];
</pre>
 
The above code will return a string object containing the string "THE QUICK BROWN FOX JUMPED" and assign it to the string2 variable. The string object referenced by string1 remains unmodified.
== Converting Strings to Numbers ==