/* NSString Two strings * str1 = @ "123"; NSString * str2 = @ "abc"; Stitching into a full string. */#import <foundation/foundation.h>int main (int argc, const char * argv[]) { /* method One * /// NSString * STR1 = @ "123";// NSString * str2 = @ "abc";/// NSString * str3 =[[nsstring alloc]initwithformat:@ "%@%@", str1,str2];// // NSLog (@ "%@", STR3); /* Method Two */nsstring * str1 = @ "123"; NSString * str2 = [str1 stringbyappendingstring:@ "abc"]; NSLog (@ "%@", str2); }
/* Append to the string @ "Price:"? An arbitrary floating-point number that is entered from the terminal, generates a new string. Two-bit decimal is required. */#import <foundation/foundation.h>int main (int argc, const char * argv[]) { NSString * str1 = @ "Price:"; float Floatnumber; scanf ("%f", &floatnumber); NSString * str2 = [[NSString alloc] initwithformat:@ "%.2f", Floatnumber]; NSString * STR3 =[[nsstring alloc]initwithformat:@ "%@%@", str1,str2]; NSLog (@ "%@", STR3); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
string concatenation, append string