Q: Why does -stringByTrimmingCharactersInSet: give me an empty string result when it shouldn't?
A: Mac OS X version 10.2 introduced a new NSString routine, -stringByTrimmingCharactersInSet:, that should return the receiver with the characters contained in the set removed from both ends of the receiver. However, if the characters to be trimmed are only at the beginning of the receiving NSString and the resulting string would be only one character long, this routine erroneously returns the empty string. This bug should be fixed in the next major release of Mac OS X. In the meantime, usage of this routine should be avoided if there is a chance that your code could fit the above buggy usage. One possible workaround, if you need to trim a mutable string and are only interested in trimming whitespace, is to use CFStringTrimWhitespace().
[Oct 9 2002]
|