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

  • Home
  • SEARCH
  • 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 8566805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:44:25+00:00 2026-06-11T17:44:25+00:00

I have an NSString instance (let’s called it myString ) containing the following UTF-8

  • 0

I have an NSString instance (let’s called it myString) containing the following UTF-8 unicode character: \xc2\x96 ( that is the long dash seen in, e.g., MS Word ).

When printing the NSString to the console using NSLog and the %@ format specifier, the character is replaced by an upside-down question mark indicating that something is wrong – and when using it as text in a table cell, the unicode character simply appears as blank space ( not the empty string – a blank space ).

To solve this, I would like to replace the \xc2\x96 unicode character with a “normal” dash – at first I thought this should be a 10 sec. task but after some research I have not yet found the “right way” to do this and this is where I would like your help.

What I have tried:

When I print myString in hex like this NSLog(@"%x", myString) I get the hex value: 96 for the unicode character representing the unicode character \xc2\x96.

Using this information I have made the following implementation to replace it with its “normal” dash equivalent:

for(int index = 0; index < [myString length]; index++)
{
    NSLog(@"Hex:'%x' Char:'%c'", [myString characterAtIndex:index],[myString characterAtIndex:index]);

    if([[NSString stringWithFormat:@"%x", [myString characterAtIndex:index]] isEqualToString:@"96"])
        myString = [myString stringByReplacingCharactersInRange:NSMakeRange(index, 1) withString:@"-"];
}

… it works, but my eyes don’t like it, and I would like to know if this can be done in much more cleaner and “right” way? E.g. like C#’s String.Replace(char,char) which supports unicode characters .

So to wrap up:

I’m looking for the “right way” to replace unicode chars in a string – I have done some research, but apparently, there is only methods available that replaces occurrences of a given NSString with another NSString.

I have read the following:

  • https://stackoverflow.com/a/5223737/700926
  • https://stackoverflow.com/a/5217703/700926
  • https://stackoverflow.com/a/714009/700926
  • https://stackoverflow.com/a/668254/700926
  • https://stackoverflow.com/a/2039396/700926

… but all of them explains how to replace a given NSString with another NSString and do not cover how specific unicode characters ( in particular double byte ) can be replaced.

  • 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-11T17:44:27+00:00Added an answer on June 11, 2026 at 5:44 pm

    You can make your string mutable (i. e. use an NSMutableString instead of an NSString). Also, the call to [[NSString stringWithFormat:@"%x", character] isEqualToString:@"96"] is as inefficient as possible – why not simply if (character == 0x96)? All in all, try

    NSString *longDash = @"\xc2\x96";
    [string replaceOccurrencesOfString:longDash withString:@"-"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following line of code: NSString *dMidiInfo = [object valueForKey:@midiInformation]; That returns
I have the following declaration in my class called GameManager: -(void)playBackgroundTrack:(NSString*)trackFileName isAmbient:(BOOL*)ambient { }
I have an NSString that as an instance variable within my appdelegate as below:
I am confused between NSString and NSMutable string usage. Suppose I have instance variables
I have an NSString that I'd like to append a { at the beginning
I have a NSString that will be passed as a parameter to my library's
Let's say I have the following headers: @interface SuperClass : NSObject @interface SubClass :
First of all, let me clarify that I know you cannot have actual abstract
i have a NSString instance ,i want to retrieve value from it and store
Have mercy, newbie here. I have a NSString value that I construct on the

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.