Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am running into URL encoding issue while connecting to Microsoft translation api from the objective c code.

The <Enter> (\n) are not getting encoded properly. Below is my code:

This is how I encode the string in IOS code before hitting http://api.microsofttranslator.com

NSString *urlEncodedString = [mytext stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

The response from the bing translation is encoded back as

NSString *response_txt = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] ;

The challenge that I am facing is, if there are enters in myText, the the translated text shows it as \u000a. For e.g.

If the input is:

 This is line 1.
 <enter>
 This is line 2. 

The Translated Text is

This is line 1.\u000aThis is line 2.

Please advise. Thanks in advance.

share|improve this question
    
Do you know that '\u000a' is the code for newline? Where is is shown that way? Using NSLog()? – Amin Negm-Awad 17 mins ago
    
yes, it is a code for new line. The thing is, 'NSString *response_txt = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] ; ' it is not replacing the 'u000a' with enter / new line. In the textbox, it is shown as 'u000a' – Sharad Kumar 13 mins ago
    
i think, i need to use stringByRemovingPercentEscapesUsingEncoding or something similar. Let me try it. – Sharad Kumar 8 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.