Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7819481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:58:09+00:00 2026-06-02T06:58:09+00:00

I created the following method which starts by using the built-in convertStringToTitleCase method on

  • 0

I created the following method which starts by using the built-in convertStringToTitleCase method on NSString but it really just capitalizes the first letter of each word. I see in .NET there is a method for TextInfo.ToTitleCase which attempts what I’d like to do with Objective-C but also falls short.

http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx

The method I wrote to start is below. How would you handle properly casing an uppercase string? Would a database of words to convert to all uppercase/lowercase help?

- (NSString *)convertStringToTitleCase:(NSString *)str {
    NSMutableString *convertedStr = [NSMutableString stringWithString:[str capitalizedString]];

    NSRange range = NSMakeRange(0, convertedStr.length);

    // a list of words to always make lowercase could be placed here
    [convertedStr replaceOccurrencesOfString:@" De " 
                                  withString:@" de " 
                                     options:NSLiteralSearch 
                                       range:range];

    // a list of words to always make uppercase could be placed here
    [convertedStr replaceOccurrencesOfString:@" Tv " 
                                  withString:@" TV " 
                                     options:NSLiteralSearch 
                                       range:range];

    return convertedStr;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:58:11+00:00Added an answer on June 2, 2026 at 6:58 am

    As noted in comments, the .NET method you refer to doesn’t do “proper” title case (that is, follow a list of exception words to be left in either all-caps or all-lowercase), so -[NSString capitalizedString] is as equivalent as you’ll get. If you want exception words, you’ll have to write your own method (or find someone else who did, as a google search for NSString "title case" might).

    How “proper” your title casing gets depends on how many exception words you’re willing to throw at it. How much of the English language do you want it to support? What about other languages? It’ll also depend on how far you go in analyzing word boundaries — you might want “TV” to stay all-caps regardless of whether it’s in quotes, at the end of a sentence, etc., but you probably also don’t want “you’ve” to come out “You’Ve”.

    If you want to process exception words, your plan of repeatedly running replaceOccurrencesOfString... will get slower the more exception words you have. (Also, using spaces in your search/replace strings means you aren’t considering other word boundaries you might want to.)

    It might be useful to consider NSRegularExpression, since regular expressions already have pretty robust notions of case and word boundaries. If that doesn’t work well for you, using a scanner to read through the input string while producing a transformed output string would be more efficient than running multiple search/replace operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some application, which is reading from System.in using the following method:
I created the following method for retrieving stored settings from the database: public String
i created the following sample method in business logic layer. my database doesn't allow
I'm following the tutorial located at: http://www.asp.net/learn/mvc/tutorial-20-cs.aspx I created my own .Menu() method to
I am using the following method to basically create a JSON string. var saveData
I have created following thing in android using android compatibility support package Basically i
Following Googles examples for using a Service, I created a couple of threads like
So I am learning MVC3 and EF4. I tried the code first method but
Using following method to create Shopping Cart Session http://net.tutsplus.com/tutorials/other/build-a-shopping-cart-in-aspnet/ Now running locally on my
I'm using the following basic function which I copied from the net to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.