Skip navigation.
 
mlRe: attributedStringByTrimmingCharactersInSet: method?
FROM : Adam R. Maxwell
DATE : Sun Jul 23 16:08:37 2006

On Jul 23, 2006, at 03:44, Keith Blount wrote:

> Hi,
>
> I want to trim the whitespace from either end of an
> attributed string. I had assumed that there would be
> an attributed variant of NSString's
> -stringByTrimmingCharactersInSet: method, which would
> make this job very easy, but there doesn't seem to be
> one. Do I need to go and write my own method to do
> this, or am I missing something really obvious?


For stuff like this you generally need to operate on the characters. 
I think the easiest way would be to create a mutable copy of your 
attributed string and then modify its mutableString directly:

CFStringTrimWhitespace((CFMutableStringRef)[mutableAttributedString 
mutableString])

NSMutableString doesn't have an equivalent of CFStringTrimWhitespace, 
and you don't want to create a new instance with 
stringByTrimmingCharactersInSet:.

hth,
Adam

Related mailsAuthorDate
mlattributedStringByTrimmingCharactersInSet: method? Keith Blount Jul 23, 12:44
mlRe: attributedStringByTrimmingCharactersInSet: method? Adam R. Maxwell Jul 23, 16:08
mlRe: attributedStringByTrimmingCharactersInSet: method? Keith Blount Jul 23, 16:16
mlRe: attributedStringByTrimmingCharactersInSet: method? Justin Anderson Jul 23, 16:44
mlRe: attributedStringByTrimmingCharactersInSet: method? Adam R. Maxwell Jul 23, 16:51