views:

111

answers:

4

Hi, 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  A: 

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

NSString *titleXML = [NSString  stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];
Ukko
First with the correct answer, but no example. I don't know if you win or not. Ha.
jshier
The example was only 30 seconds late ;-)
Ukko
+1  A: 

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\"?>"];
progrmr
+1  A: 

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

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

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\"?>"];
jshier