discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString stringWithUTF8String: length:


From: Richard Frith-Macdonald
Subject: Re: NSString stringWithUTF8String: length:
Date: Fri, 30 Jan 2004 07:05:06 +0000


On 30 Jan 2004, at 03:43, J.Aaron Pendergrass wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hey folks,
I'm working on a client for apple's daap protocol (iTunes music sharing). And it uses UTF8 string encoding when sending strings across the network, so I frequently use NSString's stringWithUTF8String: length: (or initWithUTF8String: length:), and it usually works just fine. But sometimes there is some extra garbage at the end of the NSString. For instance: The string "Hip Hop" (no quotes) sometimes becomes "Hip Hop@" and "Comedic" is sometimes "address@hidden"
"Top 25 Most Played"  comes out as "Top 25 Most Played19"  and so on.

I'm pretty sure I have the length and everything set correctly.
Does anyone know what the problem could be?

I don't know where you found a initWithUTF8String: length: method ... not in the GNUstep base library afaik.

The initialiser for use with UTF8 strings expects a nul terminated string and has no length argument. If you have a string with no nul terminator you should create an NSData object from it, then use initWithData:encoding:

Apple introduced (in macos 10.3) a new initialiser which would avoid this intermediate stage, but it's not in GNUstep yet.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]