Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - Replacing portion of string in NSString?

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>"];
like image 671
aryaxt Avatar asked Jul 12 '11 20:07

aryaxt


People also ask

How to replace string in objective C?

To replace a character in objective C we will have to use the inbuilt function of Objective C string library, which replaces occurrence of a string with some other string that we want to replace it with.

What does Nsstring mean?

A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.


1 Answers

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>"];
like image 193
John Calsbeek Avatar answered Sep 21 '22 05:09

John Calsbeek