¿Es posible incluir una comilla como parte de un nsstring del servidor?

I have a label that displays inches. I would like to display the number with the inch symbol (") or quotation mark. Can I do this with an nsstring? Thanks!

Sé que esto funciona

NSString *someString = @"This is a quotation mark: \""; NSLog(@"%@", someString );

but i am getting a data from server like this -
Video (anxiety): http://www.youtube.com/watch?v=Ii2FHbtVJzc&sns=em

so when i try to save this data in sql lite,update failed beacuse of the " in the server response

preguntado el 31 de julio de 12 a las 13:07

1 Respuestas

You can certainly include quotation marks in strings. As long as you use such strings properly, there should be no issues. You run into issues when you pass strings with quotes to methods that have special interpretation for them, such as methods that forward your strings to SQL parser. In these cases quotes need to be hidden, for example through the use of parameterized SQL statements.

However, it does not look like you are including a quotation mark in your string for a good purpose: displaying a measurement in inches is a display concern, there is absolutely no need to include the quotation mark in the server response or in the data written to the database. Instead, you should pass the measurement in its native form (an integer or a floating-point number), and add the quotation mark at the last moment, when you are about to display the string to users.

Por ejemplo, puedes hacerlo así:

int measurement = 42;
NSString *measurementDisplay = [NSString stringWithFormat:@"%d\"", measurement];

Respondido 31 Jul 12, 13:07

This is definitely correct. Just put \ in front of the quotation you want included in the string. - user717452

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.