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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:38:38+00:00 2026-06-03T04:38:38+00:00

I have a UITextField that users will be entering characters into. It is as

  • 0

I have a UITextField that users will be entering characters into. It is as simple as, how can I return it’s actual length? When the string contains A-Z 1-9 characters it works as expected but any emoji or special characters get double counted.

In it’s simplest format, this just has an allocation of 2 characters for some special characters like emoji:

NSLog(@"Field '%@' contains %i chars", myTextBox.text, [myTextBox.text length] );

I have tried looping through each character using characterAtIndex, substringFromIndex, etc. and got nowhere.

As per answer below, exact code used to count characters (hope this is the right approach but it works..):

NSString *sString = txtBox.text;

__block int length = 0;
[sString enumerateSubstringsInRange:NSMakeRange(0, [sString length]) 
                        options:NSStringEnumerationByComposedCharacterSequences
                        usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {

                            length++;                                
                        }];

NSLog(@"Total: %u", length );
  • 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-03T04:38:39+00:00Added an answer on June 3, 2026 at 4:38 am

    The [myTextBox.text length] returns the count of unichars and not the visible length of the string. é = e+´ which is 2 unichars. The Emoji characters should contain more the 1 unichar.

    This sample below enumerates through each character block in the string. Which means if you log the range of substringRange it can longer than 1.

    __block NSInteger length = 0;
    [string enumerateSubstringsInRange:range
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
        length++;
    }];
    

    You should go and watch the Session 128 – Advance Text Processing from 2011 WWDC. They explain why it is like that. It’s really great!

    I hope this was to any help.
    Cheers!

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

Sidebar

Related Questions

I have a UITextField but my users will prefer enter some number in that
I have a UITextField that I put into a UITableViewCell that I put into
I have a simple UITextField called month where I get users to simply enter
I have a UITextField that I want to set into editing mode (keyboard on
I have a UITextField that I would like to enable auto completion on by:
I have a UITextField in my app that accepts decimal amounts for prices (i.e.,
I have an UITextField and I would like that for every tap on a
I Have an a touchesEnded event that checks for when a UITextField is pressed.
So, I have a UIButton that, when a UITextField is in editing mode, becomes
I'm creating a login page for users, and I have a UITextField for users

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.