How to get all NSRange of a particular character in a NSString?

后端 未结 4 1874
醉酒成梦
醉酒成梦 2020-12-10 11:21

I have two NSStrings: orgText and searchLetter.
I want to highlight every occurrences of the searchLetter in the orgText with a re

4条回答
  •  醉酒成梦
    2020-12-10 12:08

    this is an easier way of doing it

    NSString *str = @"hello world";
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
    [attr addAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} 
                  range:[str rangeOfString:@"world"]];
    

提交回复
热议问题