0

My app contains the special character as β (ie. beta). But it is converted as Œ and its value is shown as \U0152\U2264 in NSLog().

How can i use/replace the original symbol β ?

My code is -

 NSString *str = [NSString stringWithUTF8String:"β"];

    NSString *temp = [[array2 objectAtIndex:0]valueForKey:@"Class"];
    NSString *temp1 = [[array2 objectAtIndex:0]valueForKey:@"Interactions"];


    interaction = [temp1 stringByReplacingOccurrencesOfString:str withString:@"β"];
     classes = [temp stringByReplacingOccurrencesOfString:str withString:@"β"];

     lblClass.text = classes;
  lblInteraction.text = interaction;

Thanks.

rohan panchal
  • 881
  • 3
  • 15
  • 32
  • 1
    Where do you get the symbol from? A text file? A ULR response? Make sure the original symbol is ok, and use NSUTF8Encoding when working with strings. – John Smith Jul 18 '12 at 11:19
  • @TeodorCarstea - thanks for reply. Actually that symbol comes from database(SQLite). And in database it is correct. And ya i m working with string, so how to use NSUTF8Endcoding. I have no any idea. Can you please show me? – rohan panchal Jul 18 '12 at 11:20
  • Possible Duplicate : http://stackoverflow.com/questions/9886903/iphone-how-to-write-symbol-on-a-label/9887028#9887028 – Devang Jul 18 '12 at 11:23
  • 1
    NSString *stringToDisplay = [NSString stringWithUTF8String:stringFromDatabase]; I also succest you to make sure the database has a proper encoding – John Smith Jul 18 '12 at 11:27
  • So you are getting \U0152\U2264 from your database? If so, as I already said, make sure the database holds a proper symbol, that is is in utf8, bla, bla. The problem might be not in objective c or iphone, but in your database – John Smith Jul 18 '12 at 11:37
  • @Devang - thanks for reply. I am retriving the data from database in array. Now i want to replace occurance of that unicode with that symbol. How can i do this? – rohan panchal Jul 18 '12 at 11:38
  • 1
    [yourString stringByreplacingOccurencesOfString:wrongString withString:rightString]; – John Smith Jul 18 '12 at 11:41
  • what if using "objectForKey" instead of "valueForKey" – John Smith Jul 18 '12 at 11:45
  • @rohanpanchal : you can pass your string as parameter and it will return the output which you want. – Devang Jul 18 '12 at 11:59
  • thaks both of you for helping i have solved my problem. – rohan panchal Jul 18 '12 at 12:20

1 Answers1

-1

This is for to be helpful for others .

I have solved my problem by replacing the symbol Œ with β as follows -

   NSString *temp = [[array2 objectAtIndex:0]valueForKey:@"Class"];
    NSString *temp1 = [[array2 objectAtIndex:0]valueForKey:@"Interactions"];


    interaction = [temp1 stringByReplacingOccurrencesOfString:@"Œ≤" withString:@"β"];
    classes = [temp stringByReplacingOccurrencesOfString:@"Œ≤" withString:@"β"];
rohan panchal
  • 881
  • 3
  • 15
  • 32
  • 1
    This does not fix the underlying problem at all; it's just a dirty hack for this one single instance of the problem. It will probably fail horribly if your string is, for instance, *"Sesamöl (향유) ist eine wichtige Zutat in der koreanischen Küche"*. – fzwo Jul 18 '12 at 12:37