iOS Guides | Samples

MonoTouch.Foundation.NSString Class

The Foundation String class.

See Also: NSString

Syntax

[MonoTouch.Foundation.Register("NSString", true)]
public class NSString : NSObject, INSItemProviderReading, INSItemProviderWriting, INSMutableCopying, INSSecureCoding, IDisposable

See Also

Remarks

This is a mapping to the Objective-C NSString class. Generally, in .NET languages you use the native String type in your code. In general, it is not worth using NSString in C#/Mono code as the cost of marshalling is higher when creating NSStrings manually from a C# string than letting the runtime marshal it.

There are a few cases where you will deal with NSString objects in MonoTouch. Those are cases where the NSString is used as a handle or token. That means that the underlying platform code is using the address of an NSString as a special handle (the code compares strings not by content, but by the address). In those cases, the NSString has been surfaced in the MonoTouch binding. You will typically find those as Notification constants or key constants.

Another use for NSStrings in C# code is when you want to use some localization APIs exposed in NSStrings that map directly to the underlying platform localization tables.

Code that interoperates with Objective-C automatically converts the internal C# string into an NSString. Sometimes by doing a copy of the string, although the runtime supports zero-copy marshaling of .NET strings as NSStrings as well

Related content

Requirements

Namespace: MonoTouch.Foundation
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0

The members of MonoTouch.Foundation.NSString are listed below.

See Also: NSObject

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.
Creates an NSString from a C# string.
Creates a string from a specified blob of data, using a specific encoding.

Public Fields

static readonly
EmptyNSString.

Public Properties

[read-only]
override
ClassHandleIntPtr. The handle for this class.
[read-only]
IsAbsolutePathBoolean. Whether this is an absolute path.
[read-only]
default property
Item(Int32)Char.
[read-only]
LastPathComponentNSString. The last path component of this string.
[read-only]
LengthInt32. The number of Unicode characters in this string.
[read-only]
LocalizedCapitalizedStringNSString.
[read-only]
LocalizedLowercaseStringNSString.
[read-only]
LocalizedUppercaseStringNSString.
[read-only]
PathComponentsString[]. An array of strings containing, in order, each path component of this string.
[read-only]
PathExtensionNSString. Returns this string's path extension, if it has one.

Public Methods

_characterAtIndex(Int32) : Char
The character at the specified index.
AbbreviateTildeInPath() : NSString
Converts a spath to a home-directory-relative path by substituting a tilde for the relevant portion of the path.
AppendPathComponent(NSString) : NSString
Appends the specified str in a manner that results in a path.
AppendPathExtension(NSString) : NSString
Creates a path by appending a path extension separator and then the specified str as a file extension.
AppendPaths(String[]) : String[]
Returns the array of strings created by appending this NSString to each of the specified input paths.
Capitalize(NSLocale) : String
Capitalizes a string using the rules of the specified locale.
CommonPrefix(NSString, NSStringCompareOptions) : NSString
Compare(NSString) : NSComparisonResult
Lexically compares this to the specified string.
Compare(NSString, NSStringCompareOptions) : NSComparisonResult
Compare(NSString, NSStringCompareOptions, NSRange) : NSComparisonResult
Compare(NSString, NSStringCompareOptions, NSRange, NSLocale) : NSComparisonResult
Contains(NSString) : Boolean
Copy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.
static
CreateNative(String) : IntPtr
Creates an Objective-C NSString from the C# string and returns a pointer to it.
static
CreateNative(String, Boolean) : IntPtr
DataUsingEncoding(NSStringEncoding) : NSData
DataUsingEncoding(NSStringEncoding, Boolean) : NSData
DeleteLastPathComponent() : NSString
Returns a new string by deleting the last path component of this string.
DeletePathExtension() : NSString
Returns a new string by deleting the path extension from this string.
static
DetectStringEncoding(NSData, EncodingDetectionOptions, out String, out Boolean) : UInt32
static
DetectStringEncoding(NSData, NSDictionary, out String, out Boolean) : UInt32
DrawString(PointF, UIFont) : SizeF
Deprecated in iOS7. Use NSString.DrawString(PointF, UIStringAttributes) instead. Draws the string at the given location with the given font.
DrawString(RectangleF, UIFont) : SizeF

Deprecated in iOS7. Use NSString.DrawString(PointF, UIStringAttributes) instead.

Draws the string in the specified rectangle with the specified font.

DrawString(RectangleF, UIFont, UILineBreakMode) : SizeF

Deprecated in iOS7. Use NSString.DrawString(RectangleF, UIStringAttributes) instead

Draws the string in the specified rectangle with the specified font.

DrawString(PointF, Single, UIFont, UILineBreakMode) : SizeF

Deprecated in iOS7. Use NSString.DrawString(RectangleF, UIStringAttributes) instead.

Draws the string in the specified rectangle with the specified font.

DrawString(RectangleF, UIFont, UILineBreakMode, UITextAlignment) : SizeF

Deprecated in iOS7. Use NSString.DrawString(RectangleF, UIStringAttributes) instead.

Draws the string in the specified rectangle with the specified font.

DrawString(PointF, Single, UIFont, Single, UILineBreakMode, UIBaselineAdjustment) : SizeF

Deprecated in iOS7. Use NSString.DrawString(RectangleF, UIStringAttributes) instead.

Draws the string in the specified rectangle with the specified font.

DrawString(PointF, Single, UIFont, Single, ref Single, UILineBreakMode, UIBaselineAdjustment) : SizeF

Deprecated in iOS7. Use NSString.DrawString(RectangleF, UIStringAttributes) instead.

Draws the string in the specified rectangle with the specified font.

DrawString(PointF, Single, UIFont, Single, Single, UILineBreakMode, UIBaselineAdjustment) : SizeF
Encode(NSStringEncoding) : NSData
Encode(NSStringEncoding, Boolean) : NSData
override
Equals(Object) : Boolean
static
Equals(NSString, NSString) : Boolean
ExpandTildeInPath() : NSString
Returns a new string that expands a tilde in this string (indicating the user's home dir) into a full path.
static
FromData(NSData, NSStringEncoding) : NSString
Creates an NSString from an NSData source.
static
FromHandle(IntPtr) : String
Utility method that returns a string from a pointer that points to an Objective-C NSString object.
override
GetHashCode() : Int32
Generates a hash code for the current instance.
GetLineStart(out UInt32, out UInt32, out UInt32, NSRange)
static
GetLocalizedUserNotificationString(String, NSObject[]) : String
GetVariantFittingPresentationWidth(Int32) : NSString
HasPrefix(NSString) : Boolean
HasSuffix(NSString) : Boolean
LineRangeForRange(NSRange) : NSRange
LocalizedCaseInsensitiveContains(NSString) : Boolean
static
LocalizedFormat(NSString, NSObject[]) : NSString
static
LocalizedFormat(NSString, params Object[]) : NSString
static
LocalizedFormat(String, params Object[]) : NSString
LocalizedStandardContainsString(NSString) : Boolean
LocalizedStandardRangeOfString(NSString) : NSRange
MutableCopy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.
static
PathWithComponents(String[]) : String[]
Constructs a path from the specified array of components.
static
ReleaseNative(IntPtr)
Releases a native Objective-C string.
Replace(NSRange, NSString) : NSString
Returns a new string that substitutes the replacement string into this string, at the specified range.
ResolveSymlinksInPath() : NSString
Resolves all symbolic links in this and returns the standardized path result.
StandarizePath() : NSString
Standardizes this string into a path by, for instance, removing "/./" and similar constructs.
StringSize(UIFont) : SizeF

Deprecated in iOS7. Use NSString.GetSizeUsingAttributes(UIStringAttributes) instead.

Calculates the SizeF of the specified string if it were rendered with the specified font.

StringSize(UIFont, SizeF) : SizeF

Deprecated in iOS7. Use NSString.GetBoundingRect (SizeF, NSStringDrawingOptions, UIStringAttributes,NSStringDrawingContext) instead.

Calculates the SizeF of the specified string if it were rendered with the specified font and constrained to the specified size.

StringSize(UIFont, SizeF, UILineBreakMode) : SizeF

Deprecated in iOS7. Use NSString.GetBoundingRect (SizeF, NSStringDrawingOptions, UIStringAttributes,NSStringDrawingContext) instead.

Calculates the SizeF of the specified string if it were rendered with the specified: font, size constraint, and line-break mode.

StringSize(UIFont, Single, UILineBreakMode) : SizeF

Deprecated in iOS7. Use NSString.GetBoundingRect (SizeF, NSStringDrawingOptions, UIStringAttributes,NSStringDrawingContext) instead.

Calculates the SizeF of a single line of the specified string if it were rendered with the specified: font, width constraint, and line-break mode.

StringSize(UIFont, Single, ref Single, Single, UILineBreakMode) : SizeF

Deprecated on iOS7.

Calculates the SizeF and size of the font of the first line of the specified string if it were rendered with the specified constraints.

ToLower(NSLocale) : String
Returns a new string that is the lowercase version of this string, according to the rules of the specified locale.
override
ToString() : String
Returns a string representation of the value of the current instance.
ToUpper(NSLocale) : String
Returns a new string that is the uppercase version of this string, according to the rules of the specified locale.
TransliterateString(NSString, Boolean) : NSString
TransliterateString(NSStringTransform, Boolean) : NSString

Public Operators

static
Equality(NSString, NSString)
static
Inequality(NSString, NSString)
static
Conversion to MonoTouch.Foundation.NSString(Explicit)
static
Conversion to System.String(Implicit)Converts the NSString to a CIL/C# string.