[Top][All Lists]

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

Re: NSString stringWithUTF8String: length:

From: J. Aaron Pendergrass
Subject: Re: NSString stringWithUTF8String: length:
Date: Fri, 30 Jan 2004 13:06:46 -0500

On Jan 30, 2004, at 2:05 AM, Richard Frith-Macdonald wrote:

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

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.

I was mistaken about the existence of the length parameter (noticed my mistake as soon as I sent the email). I shall try it with initWithData:encoding:

reply via email to

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