1

I have a problem with creation to NSString. The error is: "error: expected ']' before numeric constant". The code is below. Can you help me to find a solution for create these?

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version="1.0" encoding="UTF-8"?>"];

4 Answers 4

5

You need to escape the quotes in your string. Try it like this

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];
2
  • First with the correct answer, but no example. I don't know if you win or not. Ha.
    – Jon Shier
    Commented Jun 8, 2010 at 15:24
  • The example was only 30 seconds late ;-)
    – Ukko
    Commented Jun 8, 2010 at 15:45
1

You have quote characters embedded in your string, you need to escape them with backslash like this:

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];
1

You have to escape your double quotes in the string using \":

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];
1

You'll need to escape those double quotes in the string for it to work. Like so:

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.