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.

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.

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.

See Also

Deprecated

+ stringWithCString:

Creates a new string using a given C-string.

Deprecated
- initWithCString:

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.

Deprecated
+ stringWithCString:length:

Returns a string containing the characters in a given C-string.

Deprecated
- initWithCString:length:

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.

Deprecated
+ stringWithContentsOfFile:

Returns a string created by reading data from the file named by a given path.

Deprecated
- initWithContentsOfFile:

Initializes the receiver, a newly allocated NSString object, by reading data from the file named by path.

Deprecated
+ stringWithContentsOfURL:

Returns a string created by reading data from the file named by a given URL.

Deprecated
- initWithContentsOfURL:

Initializes the receiver, a newly allocated NSString object, by reading data from the location named by a given URL.

Deprecated
- writeToFile:atomically:

Writes the contents of the receiver to the file specified by a given path.

Deprecated
- writeToURL:atomically:

Writes the contents of the receiver to the location specified by a given URL.

Deprecated
- getCharacters:

Copies all characters from the receiver into a given buffer.

Deprecated
- cString

Returns a representation of the receiver as a C string in the default C-string encoding.

Deprecated
- lossyCString

Returns a representation of the receiver as a C string in the default C-string encoding, possibly losing information in converting to that encoding.

Deprecated
- cStringLength

Returns the length in char-sized units of the receiver’s C-string representation in the default C-string encoding.

Deprecated
- getCString:

Invokes getCString:maxLength:range:remainingRange: with NSMaximumStringLength as the maximum length, the receiver’s entire extent as the range, and NULL for the remaining range.

Deprecated
- getCString:maxLength:

Invokes getCString:maxLength:range:remainingRange: with maxLength as the maximum length in char-sized units, the receiver’s entire extent as the range, and NULL for the remaining range.

Deprecated
- getCString:maxLength:range:remainingRange:

Converts the receiver’s content to the default C-string encoding and stores them in a given buffer.

Deprecated
- stringByAddingPercentEscapesUsingEncoding:

Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.

Deprecated
- stringByReplacingPercentEscapesUsingEncoding:

Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.

Deprecated
- sizeWithFont:

Returns the size of the string if it were to be rendered with the specified font on a single line.

Deprecated
- sizeWithFont:forWidth:lineBreakMode:

Returns the size of the string if it were to be rendered with the specified font and line attributes on a single line.

Deprecated
- sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

Returns the size of the string if it were rendered with the specified constraints, including a variable font size, on a single line.

Deprecated
- sizeWithFont:constrainedToSize:

Returns the size of the string if it were rendered and constrained to the specified size.

Deprecated
- sizeWithFont:constrainedToSize:lineBreakMode:

Returns the size of the string if it were rendered with the specified constraints.

Deprecated
- drawAtPoint:withFont:

Draws the string in a single line at the specified point in the current graphics context using the specified font.

Deprecated
- drawAtPoint:forWidth:withFont:lineBreakMode:

Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes.

Deprecated
- drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:

Draws the string in a single line at the specified point in the current graphics context using the specified font and attributes.

Deprecated
- drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselineAdjustment:

Draws the string in a single line with the specified font and attributes, adjusting the font attributes as needed to render as much of the text as possible.

Deprecated
- drawInRect:withFont:

Draws the string in the current graphics context using the specified bounding rectangle and font.

Deprecated
- drawInRect:withFont:lineBreakMode:

Draws the string in the current graphics context using the specified bounding rectangle, font, and attributes.

Deprecated
- drawInRect:withFont:lineBreakMode:alignment:

Draws the string in the current graphics context using the specified bounding rectangle, font and attributes.

Deprecated
- drawWithRect:options:attributes:

Draws the receiver with the specified options and other display characteristics of the given attributes, within the specified rectangle in the current graphics context.

Deprecated
- boundingRectWithSize:options:attributes:

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.

Deprecated
NSMaximumStringLength

Maximum number of characters in an NSString object.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software