title: What is the right way to replace a given unicode char in an NSString instance?
body: <p>I have an NSString instance (let's called it <code>myString</code>) containing the following UTF-8 unicode character: <code>\xc2\x96</code> ( that is the long dash seen in, e.g., MS Word ).</p>
  
  <p>When printing the NSString to the console using <code>NSLog</code> and the <code>%@</code> 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 ).</p>
  
  <p>To solve this, I would like to replace the <code>\xc2\x96</code> 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.</p>
  
  <p><em>What I have tried:</em></p>
  
  <p>When I print <code>myString</code> in hex like this <code>NSLog(@"%x", myString)</code> I get the hex value: <code>96</code> for the unicode character representing the unicode character <code>\xc2\x96</code>.</p>
  
  <p>Using this information I have made the following implementation to replace it with its "normal" dash equivalent:</p>
  
  <pre><code>for(int index = 0; index &lt; [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:@"-"];
  }
  </code></pre>
  
  <p>... 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 <code>String.Replace(char,char)</code> <a href="http://msdn.microsoft.com/en-us/library/czx8s9ts.aspx" rel="nofollow noreferrer">which supports unicode characters</a> .</p>
  
  <p><em>So to wrap up:</em></p>
  
  <p>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 <code>NSString</code> with another <code>NSString</code>.</p>
  
  <p><em>I have read the following:</em></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/5223737/700926">https://stackoverflow.com/a/5223737/700926</a></li>
  <li><a href="https://stackoverflow.com/a/5217703/700926">https://stackoverflow.com/a/5217703/700926</a></li>
  <li><a href="https://stackoverflow.com/a/714009/700926">https://stackoverflow.com/a/714009/700926</a></li>
  <li><a href="https://stackoverflow.com/a/668254/700926">https://stackoverflow.com/a/668254/700926</a></li>
  <li><a href="https://stackoverflow.com/a/2039396/700926">https://stackoverflow.com/a/2039396/700926</a></li>
  </ul>
  
  <p>... but all of them explains how to replace a given <code>NSString</code> with another <code>NSString</code> and do not cover how specific unicode characters ( in particular double byte ) can be replaced.</p>