1 頁 (共 1 頁)

關於objc 的問題....

發表於 : 10/12/2004 9:32 pm
just_forever215
我是個OBJC的新手~
有些函數我不知道該怎麼運用~

- (const char *)
cString

我是想要把 NSString 轉成 cString...
然後解讀每個字...
我程式的目的是把 text中輸入" 3+5 "
解讀成數字...然後計算出來答案是8
希望有人能幫幫我...我是個新手..也沒有例子能參考..

發表於 : 10/12/2004 11:48 pm
atst
函式說明:

- (const char *)cString
Returns a representation of the receiver as a C string in the default C-string encoding. The returned C string will be automatically freed just as a returned object would be released; your code should copy the C string or use getCString: if it needs to store the C string outside of the autorelease context in which the C string is created.

Raises an NSCharacterConversionException if the receiver can’t be represented in the default C-string encoding without loss of information. Use canBeConvertedToEncoding: if necessary to check whether a string can be losslessly converted to the default C-string encoding. If it can’t, use lossyCString or dataUsingEncoding:allowLossyConversion: to get a C-string representation with some loss of information.

Use of this method is discouraged as it will be deprecated in the near future. Instead it is recommended to use UTF8String to convert arbitrary NSStrings to a lossless 8-bit representation.