I am trying to change a NSString
to resType
, As MacTypes.h
.
is defined less than four; Charcharcode / Four Characters Code / 32-bit value has been typed four times by packing a byte characters; Four letter code recycled;
I think I can use the [aString getCharacters: range:]
, but is there another straightforward way of making this conversion?
After trying out suggestions from Dawood, here's some more information.
I am using a cocoa wrapper to access the resource fork. The method I am calling is: - (NSARRA *) used terms of type: (resident) type;
If I give the hard code the value of 'RTF', then I hope I get results. I do not understand how to convert "RTF" into hard-coded values to nsstiting. I've made a test case using NSString's getCharacters and getBytes, and they all value me different integers. How do I convert nsstringing to give the same integer value as hard work? Method used: value: casted int value: hard coded (works): 'rtf' '1381254688' Lecturers: 'RTF' '5505106' betitis (ASCII): 'RTF'
Problems with recipients: Category:
This gives you UTF-16 letters ( unichar
s), while you want ASCII.
* (ResType *) [aString UTF8String]
will change the string to UTF-8 (which fits within the ASCII range equivalent to the equivalent letter of ASCII range) and then Give you the first four bytes as the ResType
value, whether it is efficient enough depends on how often you want to convert these conversions.
Another option getBytes: maxLength: usedLength: encoding: option: category: rest range:
with NSASCIIStringEncoding
or NSUTF8 string encoding Encoding set to
, the destination buffer is set to an indicator in an existing resType
variable, and the maximum length is set to 4
(or Sizeof (ResType)
).
Update:
I have found out why you are not getting the right result with my suggestion It has been found that in four-letter integer literals, byte contrast In order to be stored so that they are written. Here's an example:
#include & lt; Foundation / Foundation. H & gt; Int main () {int code = 'RTF'; Printf ("'% c% c% c% c' =% d \ n", ((four *) and code) [0], ((* four *) and code) [1], ((* four *) and Code] [2], ((four *) and code) [3], code); }
Output is 'FTR' = 1381254688
. Therefore, if you want to convert these values from NSString
, here are some options:
- Copy the string to a four-byte buffer I suggested methods ) And then it byte
0
with byte3
and byte1
with byte2
>. - Behind the same, but backwards using a standard "endianness-swapping" algorithm.
-
CharacterAtIndex:
, through the first (and only) four letters, and insert them into a four-byte buffer in reverse, remember thatcharacterAtIndex:
Gives a UTF-16 character, but it can easily be inserted as ASCII character, it is believed that it is within the ASCII range.
Comments
Post a Comment