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 7578855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:31:47+00:00 2026-05-30T17:31:47+00:00

How can I reduce an NSString to lowercase, ascii alpha characters ( /a-z/ )?

  • 0

How can I reduce an NSString to lowercase, ascii alpha characters (/a-z/)? Non-english alpha characters should be converted to ascii characters. Specifically, uppercase characters become lowercase (A → a), non-english characters become english characters (ñ → n), and all other characters are discarded.

For example: “Västerås, Sweden” becomes “vasterassweden”.

  • 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-05-30T17:31:48+00:00Added an answer on May 30, 2026 at 5:31 pm

    You can convert a string to an NSData containing bytes representing the string in a different encoding and allow for lossy conversion using dataUsingEncoding:allowLossyConversion. Then you can just convert the NSData back to an NSString:

    NSString *unicode = @"Västerås, Sweden";
    NSString *ascii = [[NSString alloc]
                       initWithData:[unicode dataUsingEncoding:NSASCIIStringEncoding
                                          allowLossyConversion:YES
                                    ]
                           encoding:NSASCIIStringEncoding
                      ];
    

    Result is “Vasteras, Sweden”. Now there is a lowercaseString method etc. if you need to go further.

    Edit:

    Oops, missed the end of the question “and all other characters are discarded”, you do wish to go further:

    NSString *lower = [ascii lowercaseString];
    NSString *letters = [[lower
                          componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet]
                                                                invertedSet]
                                                               ]
                          componentsJoinedByString:@""
                        ];
    

    That looks horrible (and a good argument to convert to a C-string and do it more directly), but it does the job: componentsSeparatedByCharactersInSet: returns an array of strings by treating the characters in the supplied set as the separators; componentsJoinedByString: joins an array of strings into a single string separated by the supplied string – and we’ve passed an empty joiner.

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

Sidebar

Related Questions

You can reduce the number of HTTP requests to speed up your site, such
Can I reduce the textbox width without using classes? <input type=text maxlength=5 style=3px/>
How can I reduce resources inside my application? I have tried a number of
Simple question :) How can I reduce build time using a parallel build /
Do any libraries or other development resources exist that can help reduce the effort
I'm a C++ developer and using Visual Studio 2008. How can I reduce *.obj
I'm trying to reduce as much as I can my VB.Net assembly side, and
I am trying to parallel a classic map-reduce problem (which can parallel well with
Are there any algorithms that can help with hierarchical clustering? Google's map-reduce has only
I'd like to see if I can reduce VM latencies by using Mono's AOT

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.