Re: Bug in NSString stringWithFormat (or sprintf)?
Re: Bug in NSString stringWithFormat (or sprintf)?
- Subject: Re: Bug in NSString stringWithFormat (or sprintf)?
- From: Chris Boot <email@hidden>
- Date: Tue, 21 Aug 2001 12:15:53 +0200
>
I may have found a bug in NSString stringWithFormat. This may or may not be
>
a bug and it may or may not be known.
>
>
If I create a string:
>
>
NSString *stringTemp = [NSString
>
stringWithFormat:@"%.4s","abcdefgh"];
>
>
stringTemp will now contain the string "abcdefgh". I was expecting just
>
"abcd".
>
>
In any other C compiler that I have worked with, if you specify a precision
>
for a character string in a format specifier, this precision says output AT
>
MOST "n" characters, but stop if you encounter a NULL byte. For this example
>
(and I got the same results with sprintf), the precision digit appears to be
>
ignored on the string specifier, and the transfer continues until a NULL
>
byte is encountered.
>
>
Is this a bug?
I dunno, but you might try "%4s" rather than "%.4s"...
--
Chris Boot
email@hidden
DOS Computers manufactured by companies such as IBM, Compaq, Tandy, and
millions of others are by far the most popular, with about 70 million
machines in use worldwide. Macintosh fans, on the other hand, may note
that cockroaches are far more numerous than humans, and that numbers
alone do not denote a higher life form.
New York Times, November 26, 1991