Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>NSString</code> has a method called <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/20000154-capitalizedString"><code>capitalizedString</code></a>:</p> <blockquote> <h3>Return Value</h3> <p>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.</p> </blockquote> <pre><code>NSString *str = @"AlgeBra"; NSString *other = [str capitalizedString]; NSLog (@"Old: %@, New: %@", str, other); </code></pre> <h2>Edit:</h2> <p>Just saw that you would like to remove accents as well. You can go through a series of steps:</p> <pre><code>// original string NSString *str = @"ÁlgeBra"; // convert to a data object, using a lossy conversion to ASCII NSData *asciiEncoded = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; // take the data object and recreate a string using the lossy conversion NSString *other = [[NSString alloc] initWithData:asciiEncoded encoding:NSASCIIStringEncoding]; // relinquish ownership [other autorelease]; // create final capitalized string NSString *final = [other capitalizedString]; </code></pre> <p>The documentation for <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html"><code>dataUsingEncoding:allowLossyConversion:</code></a> explicitly says that the letter &lsquo;Á&rsquo; will convert to &lsquo;A&rsquo; when converting to ASCII.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload