Sunday, June 2, 2013

NSMutableString appendFormat example in Objective C (iOS).

NSMutableString appendFormat

Adds a constructed string to the receiver.

- (void)appendFormat:(NSString *)format ...

Parameters of [NSMutableString appendFormat]
A format string. See “Formatting String Objects” for more information. This value must not be nil.
Important: Raises an NSInvalidArgumentException if format is nil.
A comma-separated list of arguments to substitute into format.

NSMutableString appendFormat example.
NSString *trimmedAttributeVariable = [attributeVariable
        stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


[NSM appendFormat:@"",
                                 trimmedAttributeVariable, ...

Example of [NSMutableString appendFormat].
NSMutableString's appendFormat.

NSMutableString* aString = [NSMutableString stringWithFormat:@"String with one int %d", myInt];    // does not need to be released. Needs to be retained if you need to keep use it after the current function.
[aString appendFormat:@"... now has another int: %d", myInt];

NSMutableString appendFormat example.
NSMutableString do it as following.

NSMutableString *myString = [NSMutableString stringWithString:@"some text"];
[myString appendFormat:@"some text = %d", 3];

End of NSMutableString appendFormat example article.