2011-07-04 87 views
0

我正在爲iPhone開發一個應用程序,其中我導入了C++ CLucene庫。 幾乎所有的CLucene函數都需要String作爲TCHAR*如何將NSString轉換爲/從TCHAR(使用CLucene)

我在將NSString轉換爲/從這種類型的數據中遇到了一些問題。我搜索了很多解決方案,但都沒有工作。

你能告訴我如何進行這種轉換嗎?

我能夠使用定義好的測試字符串with _T()宏使庫工作。然而,XCode給我:

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

哪個是不做過棄用的方法呢?

謝謝!

編輯: 我解決了這個辦法:

NSStringTCHAR*轉換:

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

TCHAR*NSString轉換:

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

謝謝!

+0

你可能想看看['this'](http://stackoverflow.com/questions/2610871/how-to-copy-a-wchar- t-into-nsstring)和['this'](http://stackoverflow.com/questions/891594/nsstring-to-wchar-t)。 –

回答

0

下面的代碼爲我工作:

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