Re: Strings
Re: Strings
- Subject: Re: Strings
- From: Aki Inoue <email@hidden>
- Date: Wed, 13 Feb 2002 11:00:29 -0800
Ondra,
- is it granted that with NSASCIIStringEncoding the result string will
always contain the same value for characterAtIndex:index as [rawData
bytes][index] would?
This is a quite unfortunate behavior we defined when we moved from
NEXTSTEP to OPENSTEP in order to preserve backward compatibility with
certain applications.
Since this behavior is, strictly speaking, incompatible with the rest of
encoding converters supported by NSString, you should avoid relaying on
it.
If you want to have the behavior yourself, you can manually convert each
bytes to unichar, then, use the allocated unichar buffer into NSString
via -initWithCharactersNoCopy:length:freeWhenDone:.
Aki
On 2002.02.13, at 06:03, Ondra Cada wrote:
bhaller,
email@hidden (b) wrote at Tue, 12 Feb 2002 22:37:28 -0800:
b> C strings are bad. NSString is gooood.
Incidentally...
I have to parse a quite ugly "string" data, which generally encode
values
textually, but _sometimes_ directly (it's Siemenes Gigaset 3070 log
answer to
AT^SLOGR -- anybody has direct experience with the thing, let me please
know
to share knowledge). Ie. in plain ol' stdlib I would do
something=atoi(buffer+index); // very often
something=buffer[index]; // sometimes
Whilst converting the former to the NSString level (which I do want to
use
for its power and simplicity) is naturally trivial, the latter is not:
something=[nsstr characterAtIndex:index];
might generally return Unicode values quite unrelated -- in their
numerical
values -- to what was originally in the 8-bit data.
Currently I use ...initWithData:rawData encoding:NSASCIIStringEncoding,
and
it seems to work well, but I am still not sure:
- is it granted that with NSASCIIStringEncoding the result string will
always contain the same value for characterAtIndex:index as [rawData
bytes][index] would?
- if not, is it at least granted that with NSASCIIStringEncoding the
result
string will contain exactly one character for each byte in rawData (so
that I
could use directly [rawData bytes][index] instead of
characterAtIndex:index)?
- if not, have you any idea how to parse such a thing (but for using
[rawData bytes] directly, which I don't like the slightest bit -- I use
things like hasSuffix, componentsSeparatedByString, etc. quite often)?
thanks,
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Re: Strings (From: Ondra Cada <email@hidden>) |