i have a issue , i am asking as new question as previoes one was messed
NSString *s=@"hi\nhello\n\nwelcome to this world\ni m jhon"
label.frame = ...//big enough height
label.numberOfLines = 0;
label.text = s;
this code helps me to separate string based on \n
but if i do this
NSString *s=Ad.content //where Ad.content value is **hi\nhello\n\nwelcome to this world\ni m jhon**
label.numberOfLines = 0;
label.text = s;
i am not able to sperate them by \n , what i am doing wrong here kindly suggest
Thanks
“\n” is not a special token handled by UILabel. It is, in fact, a special token handled by the compiler. When the compiler sees “Hello\nWorld”, it converts that into the sequence of characters
'H' 'e' 'l' 'l' 'o' LF 'W' 'o' 'r' 'l' 'd'(where LF is ASCII code 10, or newline). For whatever reason, yourAd.contentcontains literal “\n” sequences instead of newlines. The best solution is to look at where the content of Ad.content comes from and fix it to actually have real newlines instead of “\n” sequences. If you absolutely must have “\n” sequences, then you can use-[NSMutableString stringByReplacingOccurrencesOfString:withString:]. Of course, if anyone wants to have the literal sequence “\n” show up, then they can’t do that. If you want to support generic backslash-escaping (so the literal sequence “\n” would be represented as “\n”), then you can use a more complicated approach withNSScannerwhere you find each “\”, pull out the next character, and handle it appropriately.My recommendation is to fix
Ad.contentto contain actual newlines.