2

我有一个NSMutableAttributedString包含小写字母的值。我需要将所有小写字母转换为大写。我们可以使用uppercaseString普通字符串来解决这个问题:

[string uppercaseString];

我怎样才能改变我的情况NSMutableAttributedString?谢谢!

4

2 回答 2

3

希望下面的代码片段可以帮助你

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

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

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

NSLog(@"UpperCase   %@",linkString);
于 2014-07-10T12:47:46.740 回答
1

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"];
于 2014-07-10T12:43:22.747 回答