2

I have a weird issue, were I need to add "" after '=' symbol in nsstring. Below is the example

NSString *codes = [NSString stringWithFormat:@"%@",sessionToken];
NSString *slash = [NSString stringWithFormat:@"auth session_token=%@",codes]; << here I have to add the "".

i have tried with

NSString *slash = [NSString stringWithFormat:@"auth session_token=\"%@\"",codes];

but it didn't work the result is showing like this \"value\".

Cœur
  • 37,241
  • 25
  • 195
  • 267
Santosh Gurram
  • 1,007
  • 3
  • 13
  • 22
  • 2
    have you tried [NSString stringWithFormat:@"auth session_token=\"%@\"\"",codes]; ? – Pfitz May 29 '12 at 15:06
  • 1
    http://stackoverflow.com/questions/1934886/is-it-possible-to-include-a-quotation-mark-as-part-of-an-nsstring – Rok Jarc May 29 '12 at 15:07
  • 1
    When you say 'it's showing like `\"value\"`' how are you showing it? If it's in the debugger or as part of an NSLog of some larger object (e.g. a dictionary) you, the logging system sometimes puts the backslashes in. – JeremyP May 29 '12 at 15:35
  • @JeremyP, Yes it is showing in the debugger. Since my service has the header tag as `auth session_token="Token"`, so it is not matching since I am getting my token dynamically, I have to use the previous mentioned way i.e. `[NSString stringWithFormat:@"auth session_token=\"%@\"\"",codes]` – Santosh Gurram May 29 '12 at 18:21

2 Answers2

10

A backslash(\) followed by a quotation mark(") will inserts the quotation mark into NSString.

NSString *slash = [NSString stringWithFormat:@"auth session_token=\"%@\"",@"1233"];
NSLog(@"slash %@", slash);  

Output is

[23273:a0f] slash auth session_token="1233"  

Is it possible to include a quotation mark as part of an nsstring?

Community
  • 1
  • 1
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
-1

try this:

NSString *slash = [NSString stringWithFormat:@"auth session_token=""""""",codes];

I've recently done some thing similar and this seemed to work for me

PaulG
  • 592
  • 2
  • 8