zp26
zp26

Reputation: 1527

NSString, problem to create

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

Upvotes: 1

Views: 654

Answers (4)

Jon Shier
Jon Shier

Reputation: 12800

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

Upvotes: 1

mipadi
mipadi

Reputation: 411350

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

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

Upvotes: 1

progrmr
progrmr

Reputation: 77291

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

Upvotes: 1

Ukko
Ukko

Reputation: 2266

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

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

Upvotes: 5

Related Questions