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

  • SEARCH
  • Home
  • 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 9182903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:40:28+00:00 2026-06-17T18:40:28+00:00

I want to store different strings with different attributes and store all of them

  • 0

I want to store different strings with different attributes and store all of them in one array and then display the objects in one label but each object with its respective attribute.

Any suggestions?

EDIT: Solution derived from rmaddy’s answer

NSDictionary *redAttrs    = @{NSForegroundColorAttributeName:[UIColor redColor]};
NSDictionary *greenAttrs  = @{NSForegroundColorAttributeName:[UIColor colorWithRed:0.118 green:0.506 blue:0.000 alpha:1.000]};
NSDictionary *orangeAttrs = @{NSForegroundColorAttributeName:[UIColor orangeColor]};

NSString *stringUm = @"Brazil";
NSString *stringDois = @"USA";
NSString *stringTres = @"England";

NSMutableAttributedString *redString = [[NSMutableAttributedString alloc] initWithString:stringUm];
[redString setAttributes:redAttrs range:NSMakeRange(0,4)];

NSMutableAttributedString *greenString = [[NSMutableAttributedString alloc] initWithString:stringDois];
[greenString setAttributes:greenAttrs range:NSMakeRange(0,2)];

NSMutableAttributedString *orangeString = [[NSMutableAttributedString alloc] initWithString:stringTres];
[orangeString setAttributes:orangeAttrs range:NSMakeRange(0,4)];


NSArray *myStrings = [[NSArray alloc] initWithObjects:redString, greenString, orangeString, nil];

NSLog(@"%@", [myStrings description]);

NSMutableAttributedString *result = [[NSMutableAttributedString alloc]init];
NSAttributedString *delimiter = [[NSAttributedString alloc] initWithString: @", "];
for (NSAttributedString *str  in myStrings) {
    if (result.length) {
        [result appendAttributedString:delimiter];
    }
    [result appendAttributedString:str];
}

_lblUm.attributedText = result;
  • 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-06-17T18:40:29+00:00Added an answer on June 17, 2026 at 6:40 pm

    Your question is very unclear. But based on your comment to gerrytan’s answer, your goal is clearer.

    If you have an array of NSAttributedString objects, then you can create a single string by appending them all together with an NSMutableAttributedString.

    NSArray *myStrings = ... // your array of NSAttributedString objects
    NSMutableAttributedString *result = [[NSMutableAttributedString alloc] init];
    // Put this delimiter between each string - change as desired
    NSAttributedString *delimiter = [[NSAttributedString alloc] initWithString:@", "];
    for (NSAttributeString *str in myStrings) {
        if (result.length) {
            [result appendAttributedString:delimiter];
        }
        [result appendAttributedString:str];
    }
    
    myLabel.attributedText = result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to store different strings in one variable I can do this:
I want to store several different methods in an array in Ruby. Suppose I
i am listbox to store different strings which user gives as input. but i
If I want to store some strings or matrices of different sizes in a
I want to store the distance between different locations in a table. CREATE TABLE
I want to create 5 different files that store data from my database. I
I have an array which I store different classes which again hold different arrays.
Is it possible to store different objects that have been extended from the same
I am a new developer on Android and I want store user data in
I want to store an image in my SQLITE db. I checked out the

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.