stringWithString:
Returns a string created by copying the characters from another given string.
+ (id)stringWithString:(NSString *)aString
Parameters
- aString
- The string from which to copy characters. This value must not be
nil
.
Return Value
A string created by copying the characters from aString.
Example of [NSString stringWithString]
NSMutableString * output = [NSMutableString stringWithString:@"<ul>"];
for (NSString * item in anArray) {
[output appendFormat:@"<li>%@</li>", item];
}
[output appendString:@"</ul>"];
Example of [NSString stringWithString]
- (void):setMyString:(NSString*)newString
{
[_myString release];
_myString = [[NSString stringWithString:newString] retain];
}
Example of [NSString stringWithString]
string = @"Foo";
NSLog(@"%@ - %d", string, string);
string2 = string;
NSLog(@"%@ - %d", string2, string2);
string3 = [string copy];
NSLog(@"%@ - %d", string3, string3);
string4 = [string retain];
NSLog(@"%@ - %d", string4, string4);
string5 = [NSString stringWithString:string];
NSLog(@"%@ - %d", string5, string5);
string6 = [[NSString alloc] initWithString:string];
NSLog(@"%@ - %d", string6, string6);