NSString to wchar_t*?

送分小仙女□ 提交于 2019-11-30 08:45:48

问题


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()];


来源:https://stackoverflow.com/questions/891594/nsstring-to-wchar-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!