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
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 mails | Author | Date |
|---|---|---|
| Keith Blount | Jul 23, 12:44 | |
| Adam R. Maxwell | Jul 23, 16:08 | |
| Keith Blount | Jul 23, 16:16 | |
| Justin Anderson | Jul 23, 16:44 | |
| Adam R. Maxwell | Jul 23, 16:51 |






Cocoa mail archive

