I have this code:
// Fill out the email body text
NSString *emailBody = (@"Name:%@\nNumber of People:\nDate:", name.text);
NSLog(@"%@", emailBody);
As you can see I'm trying to append name.text to the e-mail body just after "Name:". However, NSLog only outputs the string contained in name.text and none of the rest of the e-mail body. What am I doing wrong here that the code deletes the rest of the string apart from name.text?
E.G if name.text contained the text "Jack", then NSLog would only output "Jack" and not:
Name: Jack
Number of People: x
Date: x
Which is what I am looking for.
Can anyone give me an insight as to what I'm doing wrong?
Thanks,
Jack
Use +stringWithFormat method:
NSString *emailBody = [NSString stringWithFormat:@"Name:%@\nNumber of People:\nDate:", name.text];
What you have now is a valid code, but it doesn't do what you want:
(@"Name:%@\nNumber of People:\nDate:", name.text);
calls a comma operator - it evaluates its 1st parameter, discards it and returns 2nd parameter, so that's why emailBody
is eventually filled with name.text
value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With