Instance Method インスタンスメソッド

initWithCStringNoCopy:length:freeWhenDone:

Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding. レシーバ、ある新しくアロケートされたNSStringオブジェクトを、与えられたC文字列の中のデータを省略時のC文字列符号化からユニコード文字符号化へと変換することによって初期化します。

Declaration 宣言

- (id)initWithCStringNoCopy:(char *)bytes 
                     length:(NSUInteger)length 
               freeWhenDone:(BOOL)freeBuffer;

Discussion 議論

This method converts length * sizeof(char) bytes from cString and doesn’t stop short at a zero character. cString must contain data in the default C-string encoding and may not be NULL. The receiver becomes the owner of cString; if flag is YES it will free the memory when it no longer needs it, but if flag is NO it won’t. Returns an initialized object, which might be different from the original receiver. このメソッドは、length * sizeof(char)バイトをcStringから変換します、そしてゼロ文字で立ち止まりません。cStringは、データを省略時のC文字列符号化で含まなければなりません、そしてNULLでないかもしれません。レシーバは、cStringの所有者になります;もしflagYESならばそれはメモリを自由にしますそれがもはや必要としない時に、しかしflagNOならばそれはそうしません。初期化されたオブジェクトを返します、それは元のレシーバとは異なるかもしれません。

You can use this method to create an immutable string from an immutable (const char *) C-string buffer. If you receive a warning message, you can disregard it; its purpose is simply to warn you that the C string passed as the method’s first argument may be modified. If you make certain the freeWhenDone argument to initWithStringNoCopy is NO, the C string passed as the method’s first argument cannot be modified, so you can safely use initWithStringNoCopy to create an immutable string from an immutable (const char *) C-string buffer. あなたは、このメソッドを使って、不変の文字列を不変の(const char *)C文字列バッファから作成できます。あなたが警告メッセージを受け取る場合、あなたはそれを無視できます;それの目的は、単にあなたにメソッドの最初の引数として渡されたC文字列が修正されるかもしれないことを警告することです。あなたがfreeWhenDone引数をinitWithStringNoCopyに対してNOであるように確実に手配するならば、メソッドの最初の引数として渡されるC文字列は変更されることができません、それであなたは安全にinitWithStringNoCopyを使って、不変の文字列を不変の(const char *)C文字列バッファから作成できます。

See Also 参照

Deprecated 非推奨

Related Documentation 関連文書