How do you create a formatted string like the following in Objective-C?

Tal*_*jju 1 iphone objective-c

I'm a newcomer to the iPhone world. (Previously, I've developed for android.)

I've got this code in one of my Android apps:

String body = "<Item type='Customer' id= '"+id+"'  action='delete'/>";
Run Code Online (Sandbox Code Playgroud)

What's the same in Objective-C?

mip*_*adi 6

你可以使用-[NSString stringWithFormat:]:

NSString *body = [NSString stringWithFormat:@"<Item type='Customer' id='%@' action='delete'/>", idNum];
Run Code Online (Sandbox Code Playgroud)

假设ID存储在变量中idNum.(id实际上是Objective-C中的一个类型,因此您不希望将其用作变量名.)