1

I have an issue in display sentence with a bold selected word.

NSString * string = @"Notes on iOS7 going to take a <-lot-> of getting used to!";

I want to print a sentence like this:

"Notes on iOS7 going to take a lot of getting used to!"

A plus that I have this code to select "lot" word. So how to base on this selected to bold the word. This string in this is example. So the range would be different.

NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=<-).*?(?=->)"
                                                                       options:0 error:&error];
if (regex) {
    NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:string options:0 range:NSMakeRange(0, [string length])];
    if (!NSEqualRanges(rangeOfFirstMatch, NSMakeRange(NSNotFound, 0))) {
        NSString *result = [string substringWithRange:rangeOfFirstMatch];

        NSLog(@"%@",result);
    } else {
        // Match attempt failed
    }
} else {
    // Syntax error in the regular expression
}

It will be:

Before: Notes on iOS7 going to take a <-lot-> of getting used to!

After: Notes on iOS7 going to take a lot of getting used to!

Thanks in advanced.

nvtien
  • 23
  • 7

1 Answers1

0

You have to use a NSAttributedString for that. Have a look at Any way to bold part of a NSString?

Community
  • 1
  • 1
snod
  • 2,442
  • 3
  • 20
  • 22