7

I want to append the string into single varilable using stringWithFormat.I knew it in using stringByAppendingString. Please help me to append using stringWithFormat for the below code.

NSString* curl = @"https://invoices?ticket=";
curl = [curl stringByAppendingString:self.ticket];
curl = [curl stringByAppendingString:@"&apikey=bfc9c6ddeea9d75345cd"];
curl = [curl stringByReplacingOccurrencesOfString:@"\n" withString:@""];

Thank You, Madan Mohan.

Vladimir
  • 170,431
  • 36
  • 387
  • 313
Madan Mohan
  • 8,764
  • 17
  • 62
  • 96

1 Answers1

14

You can construct your curl string using -stringWithFormat: method:

NSString *apiKey = @"bfc9c6ddeea9d75345cd";
NSString* curl = [NSString stringWithFormat:@"https://invoices?ticket=%@&apikey=%@", self.ticket, apiKey];
Vladimir
  • 170,431
  • 36
  • 387
  • 313
  • 3
    To expand on this, to append objects to a string, %@ is used such that in the above example, [self.ticket description] and [apiKey description] will be substituted in. The pass to -description is implicit. This will also let you pass in things like NSNumber using the same syntax. If you want to pass in any other datatype than objc objects, the same modifier syntax is supported as with printf() and friends; see their respective manual pages for information on what each option does. – jer Jun 16 '10 at 12:51