-3

Before start reading the question you've to know this so it'll be easy for you to understand the problem,

I've two strings verrà and verrà [see last character in both the strings -- the only difference]


I've these two strings verrà blah blah and verrà blah blah. As in my requirement, I need to show verrà blah blah based on condition, so I'll need to convert "verrÃ" to "verrà", I found that its unicode character and I can able to convert it by doing something like below,

//here, strText = @"verrà blah blah";
NSString *correctString = [NSString stringWithCString:[strText cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];

And it's working correctly for verrà blah blah, it converts it to verrà blah blah, But then I found that because of the above code, it stopped converting the already correct string that's verrà blah blah, because when this already correct string pass to the above code, it will be empty!

What I am doing wrong?

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • What exactly is the operation you are trying to perform? Is this a case conversion or something else? – Mike Weller Jul 26 '13 at 14:28
  • There's a big length string I've to show, the above word is just part of that string. I am having problem when I use the above added code to convert `verrà`. It's just working fine for `verrÃ`. Both the strings are same except the above two words. – Hemang Jul 26 '13 at 14:32
  • Your goal is unclear. What is your general need here? It makes no sense to convert a C-string in one encoding to an `NSString` with a different encoding. It will fail. – rmaddy Jul 26 '13 at 14:53
  • @rmaddy, I just want to show the string I've from the response. That's it! I do a search over google and found the above solution but that's creating the problem in different cases, that I've explained. Please let me know if you need more to know. – Hemang Jul 26 '13 at 14:56
  • If you just need to display the string then why is this question converting it? – rmaddy Jul 26 '13 at 15:00
  • Would you please read the question again? I explained well there. – Hemang Jul 26 '13 at 15:05
  • Given that I'm not the only one to ask for clarification and given the fact that no one has posted an answer should be an indication that your question isn't nearly as clear as you think it is. I've read your question several times and I don't know what you are trying to do. I know it is clear to you but it's not clear to anyone else. – rmaddy Jul 26 '13 at 20:25
  • @rmaddy, I'd updated my question, thanks for your effort, please look it once again! – Hemang Jul 27 '13 at 19:17
  • Sorry, I still don't understand. Perhaps if you included a little more code with more of the logic and the conditions. – rmaddy Jul 28 '13 at 16:50
  • @rmaddy, thanks for your efforts, I'd updated the question again, and also added the answer. :) – Hemang Aug 05 '13 at 13:20

1 Answers1

0

Finally I'd figure it out like this,

label.text = [label.text stringByReplacingOccurrencesOfString:@"Ã" withString:@"à"];

I got to know, some problems really don't need big attention or answer. I know this is a patch and not the proper way but helpful and time saver for now. Thanks everyone who've attended. :)

I'm still looking for some wide solution for such kind of conversation.

Hemang
  • 26,840
  • 19
  • 119
  • 186