Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS NSString in UTF16
    primarykey
    data
    text
    <p>I have a string that I fetched from an Apache server over HTTP:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; ... </code></pre> <p>I need to make that string a UTF16 string. I don't want to turn it into NSData. I need to keep it NSString and I need it to be in UTF16. I would be happy to put it in an NSData object even, if I could do it as UTF16. I'm doing something similar now:</p> <pre><code>[self.returnedData appendData:data]; </code></pre> <p>But that still transfers it as UTF8. It's probably simple and I'm missing it. But I don't find it in the Apple docs or this site, and my Google-Fu has failed me. What am I missing? How do I do that? Thanks for your time and help.</p> <p>EDIT: Ok. All of what you and Justin have said makes sense and makes things make more sense. So this is what I am doing. It seems to be correct from this line but I wanted to make sure I am understanding you correctly. </p> <pre><code>NSData *resultData = [self. result dataUsingEncoding:NSUTF16LittleEndianStringEncoding]; NSString *resultStr = [[NSString alloc] initWithData:resultData encoding:NSUTF16LittleEndianStringEncoding]; NSString *md5Result = [[NSString stringWithFormat:@"%@",[resultStr MD5]] uppercaseString]; NSLog(@"md5Result = %@",md5Result); </code></pre> <p>That last part is what I am doing with the string after it's UTF-16. I have a category that makes it an MD5 hex string similar to <a href="http://blog.blackwhale.at/?tag=hmac" rel="nofollow">http://blog.blackwhale.at/?tag=hmac</a> Thanks again. I'll bump you guys both and say this is the right answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload