views:

193

answers:

1

Hey guys I have an NSString that has an ó inside, so when I put it in a TextView insted of reading "ó" I reads "A³".

So this is what I did:

self._Direccion = [self._Direccion stringByReplacingOccurrencesOfString:@"ó­" withString:@"ó"];

but it's not working, I don't know why...

Is working for this:

/* á*/ self._Direccion = [self._Direccion stringByReplacingOccurrencesOfString:@"á" withString:@"á"];

/* é */ self._Direccion = [self._Direccion stringByReplacingOccurrencesOfString:@"é" withString:@"é"];

/* í */ self._Direccion = [self._Direccion stringByReplacingOccurrencesOfString:@"í" withString:@"í"];

/* ú */ self._Direccion = [self._Direccion stringByReplacingOccurrencesOfString:@"ú" withString:@"ú"];

but is not working with the "ó" why´s that?

Best Regards Carlos Vargas

+2  A: 

This is a string encoding issue that you should not fix by manually replacing characters but by building those strings with the right encoding at the very point where you initialize them.

If those strings come from some database with a different encoding than UTF-8 then you can specify that encoding to NSString by using for example:

NSString* string = [NSString stringWithCString: buffer
    encoding: NSISOLatin2StringEncoding];

Make sure understand how the source encodes strings first. There are many stringencoding types but the iPhone will support most of them.

St3fan
I already done stringEncoding and whit NSISOLatin2StringEncoding it gives me this: "ĂÂł" instead of "ó", that's why I tried to replace it by myself
Carlos Vargas
Well then it probably is not ISO Latin-2.
St3fan
actually I've tried with all the NSStringEnconding Format I've found and non of them worked
Carlos Vargas