I have a display like in the picture

Im getting this from a string str which is like below

Code I have tried
lbl1.text=newStr;
NSString *textxtra = @"Xtra";
NSString *textremove = @"Remove";
NSMutableAttributedString *attrsString = [[NSMutableAttributedString alloc] initWithAttributedString:lbl1.attributedText];
// search for word occurrence
NSRange range = [lbl1.text rangeOfString:textxtra];
NSRange range1 = [lbl1.text rangeOfString:textremove];
if (range.location != NSNotFound) {
[attrsString addAttribute:NSForegroundColorAttributeName value:[UIColor systemGreenColor] range:range];
}
if (range1.location != NSNotFound) {
[attrsString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
}
// set attributed text
lbl1.attributedText = attrsString;
How to get the string before Xtra (American Cheese) and after Xtra($1) in green color ?
The part before Remove(House Mayo) in red color?
i.e The whole string American Cheese: Xtra $1 should be in green color.
I get the idea to take the string in between \n.
i.e string before Xtra upto \n and after Xtra upto \n
But couldn't understand exactly how to implement
Any ideas/suggestions will be helpful
rangeOfString:options:range:to search for"\n", using the options backwards, and the range to search, being0, rangeOfXtra.location. Then, you'll can calculate the range:(rangeOfN.location, rangeOfXtra.location - rangeOfN.location). Repeat for the other one.NSStringseparated with"\n", create aNSMutableAttributedStringempty, iterate over each string, and if the line contain one of the world, add the color effect to the whole line, and append to the attributedString.