13

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>"];
0

1 Answer 1

25

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>"];
Sign up to request clarification or add additional context in comments.

2 Comments

It seems like the method "stringByReplacingOccurrencesOfString" return a new string with the replacement and it doesn't actually modify the current string
@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....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.