I am using the following code to replace a portion of the string, this works for normal characters (alphabetical characters) but when it comes to symbols like "•" it can't replace the character.

Any solution?

[myString stringByReplacingOccurrencesOfString:@"•" withString:@"<BULLET_POINT>"];

You may not be able to literally insert non-ASCII characters like "•" in a source file. Try using the escape \u2022 instead.

myString = [myString stringByReplacingOccurrencesOfString:@"\u2022" withString:@"<BULLET_POINT>"];
  • It seems like the method "stringByReplacingOccurrencesOfString" return a new string with the replacement and it doesn't actually modify the current string – aryaxt Jul 12 '11 at 20:52
  • 2
    @aryaxt: that's right, and is because NSString is an immutable object. If you have an NSMutableString you can use replaceOccurrencesOfString:withString:options:range: instead of stringByReplacingOccurrencesOfString.... – Tommy Jul 12 '11 at 21:01

Your Answer

