Anand Gautam
Anand Gautam

Reputation: 2579

How to change case of an NSMutableAttributedString in Objective-C?

I have a NSMutableAttributedString that contain values in lower case letters. I need to convert all the lowercase letters to uppercase. We can solve this using uppercaseString for normal string as:

[string uppercaseString];

How can I change my case for NSMutableAttributedString? Thanks!

Upvotes: 2

Views: 6408

Answers (2)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

NSMutableAttributedString class doesn't have uppercaseString method. So you can use like this..

NSString *str = @"objective-c";

str = [str uppercaseString];

NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str];
NSLog(@"Attributed String %@",attStr);

And You wanna upper latter in particular range then do something like this...

[attStr replaceCharactersInRange:NSMakeRange(0, 1) withString:@"O"];

Upvotes: 1

Blisskarthik
Blisskarthik

Reputation: 1242

Hope the below code snippet may help you

NSMutableAttributedString * linkString = [[NSMutableAttributedString  alloc]initWithString:@"Google"];

NSString * strings = [[linkString string]uppercaseString];

[linkString replaceCharactersInRange:NSMakeRange(0, [linkString length]) withString:strings];

NSLog(@"UpperCase   %@",linkString);

Upvotes: 3

Related Questions