Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position of a character in a NSString or NSMutableString

Tags:

People also ask

What is NSMutableString?

NSMutableString is the abstract base class for a cluster of classes representing strings whose contents can be changed. It inherits from NSString. It extends the interface it inherits from NSString by adding methods to change the string contents.

What is NSMutableString in swift?

The NSMutableString class declares the programmatic interface to an object that manages a mutable string—that is, a string whose contents can be edited—that conceptually represents an array of Unicode characters.


I have searched for hours now and haven't found a solution for my problem. I have a NSString which looks like the following:

"spacer": ["value1", "value2"], "spacer": ["value1", "value2"], ...

What I want to do is to remove the [ ] characters from the string. It's seems to be impossible with objective-c. Most other programming languages offer functions like strpos or indexOf which allow me to search for a character or string and locate the position of it. But there seems nothing to be like this in objective-c.

Does anyone has an idea on how to remove these characters? Additionally there are [] characters in the string which should remain, so I can't just use NSMutableString stringByReplacingOccurencesOfString:withString. I need to search first for the spacer string and then remove only the next two [] chars.

Thank you for helping me.