1

I have an NSString that contains a value "\U2212" instead of "-" which is coming from API. When I tried to replace this string with needed character using subString occurrence method it shown error. So how do I replace my NSString that contains "\U2212" with "-". I tried the following code. Please help me. I searched many things but nothing helped. Thanks in advance.

input:"(UTC\U221206:00) Canada/Central"

Desired output:"(UTC-06:00) Canada/Central"

code:

NSString *timezoneDisplayValue = [timezone valueForKey:@"tomeZoneDisplayValue"];
timezoneDisplayValue = [timezoneDisplayValue stringByReplacingOccurrencesOfString:@"\U2212" withString:@"-"];
Shai
  • 25,159
  • 9
  • 44
  • 67
Augustin Jose
  • 350
  • 3
  • 12
  • `\U2212` ? `\\U2212`? `\U0002212`? – Larme Apr 15 '15 at 14:06
  • What are the bets that you are misinterpreting the output of an NSLog statement? U2212 is a Unicode "minus sign". What makes you think you need to replace it? – gnasher729 Apr 15 '15 at 14:08
  • my Api is returning like that. So I need to replace this with - – Augustin Jose Apr 15 '15 at 14:09
  • Are you sure that the string is holding "\U2212" before replacing it. I would assume it is holding "\\U2212" before replacing. Correct me if I'm wrong. – Mahi Apr 15 '15 at 15:30

1 Answers1

0

below code returns YES or NO, whether your string has any encoding...

[apiString canBeConvertedToEncoding:NSASCIIStringEncoding];

If NO is returned, then convert with the correct encoding type :

[apiString dataUsingEncoding:NSUTF16BigEndianStringEncoding];
keepsmiling
  • 370
  • 1
  • 13