• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Make an attributed string all uppercase without losing attributes?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make an attributed string all uppercase without losing attributes?


  • Subject: Make an attributed string all uppercase without losing attributes?
  • From: Graham Cox <email@hidden>
  • Date: Sat, 9 May 2009 12:56:47 +1000

I have an attributed string. I want to preserve the attributes within the string but set all the actual characters to uppercase, lowercase, etc.

According to the docs for NSMutableAttributedString, the - mutableString method returns a mutable string that the receiver tracks changes to in order to preserve attribute runs. However, when I call - setString: or -replaceCharactersInRange:withString: on this, all my attributes are removed.

How can I do this without my attributes going AWOL?




NSMutableAttributedString* ttd = [[[self textSubstitutor] substitutedStringWithObject:object] mutableCopy];

// capitalize all the text according to the capitalization setting:

NSMutableString* mStr = [ttd mutableString];


// Docs: "Discussion
// The receiver tracks changes to this string and keeps its attribute mappings up to date."

NSRange range = NSMakeRange( 0, [mStr length]);

switch([self capitalization])
{
default:
break;

case kDKTextCapitalizationUppercase:
[mStr replaceCharactersInRange:range withString:[mStr uppercaseString]]; // setString: doesn't work either
break;

case kDKTextCapitalizationLowercase:
[mStr replaceCharactersInRange:range withString:[mStr lowercaseString]];
break;

case kDKTextCapitalizationCapitalize:
[mStr replaceCharactersInRange:range withString:[mStr capitalizedString]];
break;
}


tia,


--Graham _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Make an attributed string all uppercase without losing attributes?
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: quick and dirty NSData implosion
  • Next by Date: Re: NSXMLParser frees itself on error?
  • Previous by thread: Re: converting a characer to a keycode
  • Next by thread: Re: Make an attributed string all uppercase without losing attributes?
  • Index(es):
    • Date
    • Thread