I can't seem to find a good built-in way to convert an NSString to wchar_t... any tips on how to do this? Anything Apple exposes on the NSString class is for c-strings (char*) or for unichars, but nothing for wchar*.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
[urString cStringUsingEncoding:NSUTF16LittleEndianStringEncoding]
wchar_t
is compiler specific. Assuming you wan the Win32 wchar_t
, then UTF16 little ending encoded will do it. For Unix wchar_t
you may need the NSUTF32 encoding family, with your platform of choice endianess.
回答2:
Following code worked for me: (not sure if this will be applicable for wchar_t as well)
NSString *pStr = [NSString stringWithFormat:@"%S", GetTCHARString()];