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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:16:51+00:00 2026-06-13T23:16:51+00:00

I was getting the NSString from UIWebView which contain iPhone emoji and reversing text

  • 0

I was getting the NSString from UIWebView which contain iPhone emoji and reversing text excluding emoji. I need to display reverse of NSString again in UIWebView but couldn’t get the reversed string with emoji. I am not identifying the emoji character in string. I have xcode 4.5 with iOS 6.0. here is my code:

 - (NSString *) createReverseStringFromString:(NSString *)inputString {
  if (inputString.length <= 0)
    return inputString;

 NSMutableString *mutableReverseString = [[NSMutableString alloc] 
 initWithCapacity:inputString.length];
 Thfor (NSInteger i = inputString.length -1; i >= 0; i--) {

    NSString *characterString = [inputString substringWithRange:NSMakeRange(i, 1)];
    [mutableReverseString appendString:characterString];

    NSLog(@"mutableReverseString..%@",mutableReverseString);
 }

 NSString *outputString = [mutableReverseString copy];
 [mutableReverseString release];
return [outputString autorelease];
 }
  • 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-13T23:16:52+00:00Added an answer on June 13, 2026 at 11:16 pm

    The problem is that many emoji characters are internally stored as a “surrogate pair” of two characters.

    For example, “THUMBS UP SIGN” is Unicode point U+1F44D, but if you store it in an NSString and use substringWithRange to get single characters, you will get two characters:

    U+D83D, U+DC4D
    

    which is the UTF-16 surrogate pair for U+1F44D.

    Of course, if you reverse these two characters, the output is garbage.

    The solution is to use rangeOfComposedCharacterSequenceAtIndex to get sequences of characters which “belong together”:

    - (NSString *) createReverseStringFromString:(NSString *)inputString {
        if (inputString.length <= 0)
            return inputString;
    
        NSMutableString *mutableReverseString = [[NSMutableString alloc] 
                             initWithCapacity:inputString.length];
    
        NSInteger i = inputString.length;
        while (i > 0) {
            NSRange range = [inputString rangeOfComposedCharacterSequenceAtIndex:i-1];
            NSString *characterString = [inputString substringWithRange:range];
            [mutableReverseString appendString:characterString];
            i = range.location;
        }
    
        NSString *outputString = [mutableReverseString copy];
        return outputString;
    }
    

    This function correctly reverses strings containing emoji characters.

    (Note: I have omitted all release, autorelease calls because I always compile with ARC. You have to add that again where appropriate.)

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

Sidebar

Related Questions

I am getting data from server it gives in response a NSString which hase
I am getting the values from UITextfield into NSString , need to convert the
Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
I'm getting an NSString from a dictionary that needs to have a variable integer,
having issues getting a value from a NSString in my view controller to my
getting text from a .rtf file : this is what i've got so far...
I am getting NSString 2012-08-17T10:56:45.508205 as time from Django API. I am trying to
i getting data from my site: NSString *website = [NSString stringWithFormat:@http://www.mysite.com/fbconnect.php?email=%@&name=%@&pass=***, nameTrimmmed, [jsonObject objectForKey:@email]];
I need to remove/replace all characters except for alpha numeric, -, & from NSString.
Currently I am getting the values from statement like this: [[NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,0)] retain];

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.