开发者

How to convert NSString to/from TCHAR (using CLucene)

开发者 https://www.devze.com 2023-03-17 17:24 出处:网络
I\'m developing an application for iPhone, in which I\'ve imported c++ CLucene library. Almost all CLucene functiona require String as TCHAR*.

I'm developing an application for iPhone, in which I've imported c++ CLucene library. Almost all CLucene functiona require String as TCHAR*.

I've some problems in converting NSString to/from this type of data. I've searched many solution but none worked.

Can you please show me how to make this conversion?

I was able to make library work with test string defined with _T() macro. However XCode give me:

Conversion from string literal to 'TCHAR *' (aka 'wchar_t *') is deprecated.

Which is the non deprecated method t开发者_C百科o do it?

Thank you!

Edit: I solved this way:

Converting from NSString to TCHAR*:

(const TCHAR *) [stringa cStringUsingEncoding:NSUTF32LittleEndianStringEncoding];

Converting from TCHAR* to NSString:

[[NSString alloc] initWithBytes:ctc length:wcslen(ctc) *  sizeof(TCHAR)  encoding:NSUTF32LittleEndianStringEncoding]

thank you!


Following code worked for me:

NSString *pStr = [NSString stringWithFormat:@"%S", GetTCHARString()];
0

精彩评论

暂无评论...
验证码 换一张
取 消