String concatenation and substitution in the development, it is used in the frequent and some things don’t pay attention to error, it is easy to enter stringByReplacingOccurrencesOfString doesn’t work is a:

NSMutableString *halfUrlStr = [NSMutableString stringWithFormat:@"%@",[LCReqURLManager requestWithURL:LC_MYINVEST_AUTH_BUYHISTORY]];

[halfUrlStr stringByReplacingOccurrencesOfString:@"{packageId}" withString:proID];

NSString *requestStr = [NSString stringWithFormat:@"%@%@",kUrlPreDomain,halfUrlStr];
Copy the code

NSMutableString = NSMutableString = NSMutableString = NSMutableString

// The correct way NSString *halfUrlStr = [NSString stringWithFormat:@"%@",[LCReqURLManager requestWithURL:LC_MYINVEST_AUTH_BUYHISTORY]]; halfUrlStr = [halfUrlStr stringByReplacingOccurrencesOfString:@"{packageId}" withString:proID]; NSString *requestStr = [NSString stringWithFormat:@"%@%@",kUrlPreDomain,halfUrlStr];Copy the code

It would be nice to do an assignment, but you can’t do it directly. Oddly enough, this is how Apple explained the sentence:

/* Replace characters in range with the specified string, returning new string.
Copy the code

Returns a new string, it seems that this doesn’t really matter, can direct operation method is also exist, such as stringByAppendingString, so it was very strange, when using stringByReplacingOccurrencesOfString or an assignment to do the operation, Jump over the hole.