Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:33:40+00:00 2026-05-31T04:33:40+00:00

I am trying to make multiple occurrences in a attributed string bold using something

  • 0

I am trying to make multiple occurrences in a attributed string bold using something like the following

[attrStr setFont:[UIFont ...] range:[attrStr.string rangeOfString:@"hello world"]];

As you know, ‘rangeOfString’ always return the FIRST occurrence of the match… I am still quite new to iOS, just wondering what’s the best way to set all occurrences to bold… Is there any function provided in NSString or something?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:33:41+00:00Added an answer on May 31, 2026 at 4:33 am

    You should first try to get all ranges in the string and then set the attribute for every range. There are some great code examples right here on stackoverflow: https://stackoverflow.com/a/4653266/381870

    Edit:

    Here’s an example for you

    - (NSArray *)rangesOfString:(NSString *)searchString inString:(NSString *)str {
        NSMutableArray *results = [NSMutableArray array];
        NSRange searchRange = NSMakeRange(0, [str length]);
        NSRange range;
        while ((range = [str rangeOfString:searchString options:0 range:searchRange]).location != NSNotFound) {
            [results addObject:[NSValue valueWithRange:range]];
            searchRange = NSMakeRange(NSMaxRange(range), [str length] - NSMaxRange(range));
        }
        return results;
    }
    

    Usage:

    NSArray *results = [self rangesOfString:@"foo" inString:@"foo bar foo"];
    NSLog(@"%@", results);
    

    gives you

    (
        "NSRange: {0, 3}",
        "NSRange: {8, 3}"
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a multiple page application using winforms. I decied to
I'm trying to make a MATCH of columns using multiple criteria, as in the
I'm trying to make a multi file uploader. I'm using Multiple File Upload Magic
I'm trying to make system of multiple dialogs in one page using jquery dialog...
I've been trying to make a module, command-line-like application. Each module can hold multiple
Im trying to make multiple quizes that will keep track of each quiz on
I'm trying to use a ClientBundle in my GWT application to make multiple images
I'm trying to make a webpage that allows the uploading of multiple files at
I'm trying to make a search feature that will search multiple columns to find
I am trying to make a PointCloud mapping user with multiple kinects on Processing.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.