NSMutableString *a = @"Hi";
NSMutableString *b =[a stringByAppendingString:@"\n\n Hi Again"];
The above doesn't give an error but does not put "Hi Again" on the next line. Why?
NSMutableString *a = @"Hi";
NSMutableString *b =[a stringByAppendingString:@"\n\n Hi Again"];
The above doesn't give an error but does not put "Hi Again" on the next line. Why?
EDIT2 I realised after posting, that the OP had NSString in the title but put NSMutableString in the code. I have submitted an edit to change the NSMutableString to NSString.
I will leave this as it still maybe helpful.
Well I am surprised that does not give an error, because you are giving a NSMutableString a NSString.
You need to read the Documentation on NSMutableStrings.
to give you an idea
//non mutable strings
NSString *shortGreetingString = @"Hi";
NSString *longGreetingString = @"Hi Again";
/*mutable string - is created and given a character capacity The number of characters indicated by capacity is simply a hint to increase the efficiency of data storage. The value does not limit the length of the string
*/
NSMutableString *mutableString= [NSMutableString stringWithCapacity:15];
/*The mutableString, now uses an appendFormat to construct the string
each %@ in the Parameters for the appendFormat is a place holder for values of NSStrings
listed in the order you want after the comma.
Any other charactars will be included in the construction, in this case the new lines.
*/
[mutableString appendFormat:@"%@\n\n%@",shortGreetingString,longGreetingString];
NSLog (@"mutableString = %@" ,mutableString);
[pool drain];
Try using NSString
. You could use:
NSString *a = [NSString stringWithFormat:@"%@\n\n%@", @"Hi", @"Hello again"]
If your string is going in a UIView (e.g a UILabel), you also need to set the number of lines to 0
myView.numberOfLines=0;