Hi, I'm having trouble with NSString - I'm capturing NSTextField edits and 
analyzing the typed (uni-)chars:

{
        int bufsize = 3*sizeof(unichar) ;
        static unichar *buf = nil ;
        if( nil == buf )
        {
                buf = (unichar*) malloc( bufsize ) ;
                if( nil != buf )
                {
                        buf[ 2 ] = 0 ;
                } else {
                        NSLog(@"textDidChange: malloc error");
                        return ;
                }

        }
        
        NSString * s = [textField stringValue] ;
        
        // could put this in a loop, but I'm only handling 2 characters, so...

        if( 0 < [s length] )
        {
                buf[0] = [s characterAtIndex:0];
                buf[1] = 0 ;
        }
        
        if( 1 < [s length] )
        {
                buf[1] = [s characterAtIndex:1];
        }

        // buf is set to the character string properly...

        s = [NSString stringWithCString:(const char *)buf encoding: 
NSUnicodeStringEncoding] ;
        
        NSInteger s_len = [s length]; //s_len is always zero
}

if I change the encoding: to ascii, I get one character in the new NSString, as 
I'd expect, but with Unicode encoding, I get no characters - WHY?!

Thanks In Advance,

Gabe


----------------------------------------------------------------
Gabriel Fernandez
Wheel Software

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to