Replace occurrences of NSString - iPhone

I have a long NSString in which I m trying to replace special characters. Part of my string looks like this:

"veau (c\u00f4telette)","veau (filet)","agneau (gigot)","agneau (c\u00f4telette)","b**\u0153**uf (hach\u00e9)","porc (hach\u00e9)"

I would like to replace all the \u0153 with "oe". I've tried:

[response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];

but it doesn't work.... I don't understand why!

Answers


The backslash is an escape character, so if you want to specify the actual backslash character in a string literal, you need to use two backslashes.

NSString *new = [old stringByReplacingOccurrencesOfString: @"\\u0153" withString:@"oe"];

NSString is immutable, so the function generates a new string that you have to store:

NSString *new = [old stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];

Need Your Help

Unit Testing with items that need to send headers

php unit-testing phpunit

I'm currently working with PHPUnit to try and develop tests alongside what I'm writing, however, I'm currently working on writing the Session Manager, and am having issues doing so...

How do you cut off text after a certain amount of characters in PHP?

php string strip

I have two string that i want to limit to lets say the first 25 characters for example. Is there a way to cut off text after the 25th character and add a ... to the end of the string?