Skip navigation.
 
mlRe: stringByTrimmingCharactersInSet (work-around)
FROM : Jacob Engstrand
DATE : Sat Nov 23 07:09:24 2002

Hi All.

One work-around is to simply append a space to the string before
trimming. Like this:

    value = [value stringByAppendingString: @" "];
    value = [value stringByTrimmingCharactersInSet: [NSCharacterSet
whitespaceCharacterSet]];

Not pretty, but the good thing is this code will continue to work after
Apple fixes stringByTrimmingCharactersInSet:.

/jak



> Hi All,
>
>    NSString *before = @"ab";
>    NSLog(@"before: '%@'", before);
>    NSString *after = [before stringByTrimmingCharactersInSet:
> [NSCharacterSet whitespaceCharacterSet]];
>    NSLog(@"after: '%@'", after);
>
> The above piece of code outputs:
>
>    before: 'ab'
>    after: 'ab'
>
> Which is ok, of course. But changing the first line to:
>
>    NSString *before = @"a";
>
> gives the following output:
>
>    before: 'a'
>    after: ''
>
> What gives? Is it me? Am I loosing it? Or is this some bug that
> everybody knows about but I?
>
> /jak

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlRe: stringByTrimmingCharactersInSet (work-around) Jacob Engstrand Nov 23, 07:09
mlRe: stringByTrimmingCharactersInSet (work-around) Ali Ozer Nov 23, 07:46
mlRe: stringByTrimmingCharactersInSet (work-around) Jacob Engstrand Nov 23, 07:59