NSString to wchar_t*?

2020-02-11 06:36发布

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*.

2条回答
Anthone
2楼-- · 2020-02-11 06:43
[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.

查看更多
你好瞎i
3楼-- · 2020-02-11 07:00

Following code worked for me: (not sure if this will be applicable for wchar_t as well)

NSString *pStr = [NSString stringWithFormat:@"%S", GetTCHARString()];
查看更多
登录 后发表回答