Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Bug in NSString's stringByTrimmingCharactersInSet?

Bug in NSString's stringByTrimmingCharactersInSet?
Thread Tools
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Oct 29, 2002, 05:28 PM
 
I'm having a very frustrating problem with an application I'm developing, and I've narrowed it down to a single line of code. I've been able to write a tiny little application which demonstrates the problem...

The NIB file consists of a single window which has two NSTextFields and one button. The first field, "inField" allows text entry. The second field, "outField" has text placed in it by the "trim" action invoked by the button.

(I hope I'm making sense so far... the code below should help understand what I've written above).

The "trim" action is supposed to take the text from "inField", trim whitespace from the beginning and end of the text, and place the result in "outField".

In most cases this works, however if a single character (with no whitespace) is entered in "inField", the "trim" action results in an empty string!!!

The entire code of the test application is below...

Interface:

Code:
#import <Cocoa/Cocoa.h> @interface Blah : NSObject { IBOutlet NSTextField *inField; IBOutlet NSTextField *outField; } - (IBAction)trim:(id)sender; @end
Implementation:

Code:
#import "Blah.h" @implementation Blah - (IBAction)trim:(id)sender { [outField setStringValue: [[inField stringValue] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet] ] ]; } @end
Any ideas on what I'm doing wrong, or is this a bug in the NSString method?
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Oct 30, 2002, 03:54 PM
 
Anyone? Can someone at least replicate the problem?

If this is a bug in Cocoa (NSString), how do I report it to Apple?
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Oct 31, 2002, 12:33 PM
 
Originally posted by Brass:
If this is a bug in Cocoa (NSString), how do I report it to Apple?
go to http://connect.apple.com
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 31, 2002, 01:04 PM
 
Originally posted by tobli:


go to http://connect.apple.com
No! don't - they know:

http://developer.apple.com/qa/qa2001/qa1202.html
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 31, 2002, 01:05 PM
 
Originally posted by Diggory Laycock:


No! don't - they know:

http://developer.apple.com/qa/qa2001/qa1202.html
wow - reading ADC news finally paid off.
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Oct 31, 2002, 03:43 PM
 
EXCELLENT! Thanks for this. At least I now know how to work around the bug!!!

I'll have to start actually reading those ADC emails I get.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:16 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2