NSString Class

Definition

The Foundation String class.

[Foundation.Register("NSString", true)]
public class NSString : Foundation.NSObject, AppKit.INSPasteboardReading, AppKit.INSPasteboardWriting, CloudKit.ICKRecordValue, Foundation.INSItemProviderReading, Foundation.INSItemProviderWriting, Foundation.INSMutableCopying, Foundation.INSSecureCoding, IDisposable
type NSString = class
    inherit NSObject
    interface INSCoding
    interface INativeObject
    interface IDisposable
    interface INSCopying
    interface INSItemProviderReading
    interface INSItemProviderWriting
    interface INSMutableCopying
    interface INSSecureCoding
    interface INSPasteboardReading
    interface INSPasteboardWriting
    interface ICKRecordValue
Inheritance
NSString
Derived
Attributes
Implements

Remarks

This is a mapping to the Objective-C NSString class. Generally, in .NET languages you use the native T:System.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

Constructors

NSString()

Default constructor that initializes a new instance of this class with no parameters.

NSString(IntPtr)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

NSString(NSCoder)

A constructor that initializes the object from the data stored in the unarchiver object.

NSString(NSData, NSStringEncoding)

Creates a string from a specified blob of data, using a specific encoding.

NSString(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

NSString(String)

Creates an NSString from a C# string.

NSString(String, Int32, Int32)

Fields

Empty

Properties

Class (Inherited from NSObject)
ClassHandle

The handle for this class.

DebugDescription

A developer-meaningful description of this object.

(Inherited from NSObject)
Description

Description of the object, the Objective-C version of ToString.

(Inherited from NSObject)
Handle

Handle (pointer) to the unmanaged object representation.

(Inherited from NSObject)
IsAbsolutePath

Whether this is an absolute path.

IsDirectBinding (Inherited from NSObject)
IsProxy (Inherited from NSObject)
Item[nint]
LastPathComponent

The last path component of this string.

Length

The number of Unicode characters in this string.

LocalizedCapitalizedString
LocalizedLowercaseString
LocalizedUppercaseString
PathComponents

An array of strings containing, in order, each path component of this string.

PathExtension

Returns this string's path extension, if it has one.

ReadableTypeIdentifiers
RetainCount

Returns the current Objective-C retain count for the object.

(Inherited from NSObject)
Self (Inherited from NSObject)
Superclass (Inherited from NSObject)
SuperHandle

Handle used to represent the methods in the base class for this NSObject.

(Inherited from NSObject)
WritableTypeIdentifiers
WritableTypeIdentifiersForItemProvider
Zone (Inherited from NSObject)

Methods

AbbreviateTildeInPath()

Converts a spath to a home-directory-relative path by substituting a tilde for the relevant portion of the path.

AddObserver(NSObject, NSString, NSKeyValueObservingOptions, IntPtr)

Registers an object for being observed externally (using NSString keyPath).   Observed changes are dispatched to the observer’s object ObserveValue(NSString, NSObject, NSDictionary, IntPtr) method.

(Inherited from NSObject)
AddObserver(NSObject, String, NSKeyValueObservingOptions, IntPtr)

Registers an object for being observed externally (using string keyPath).   Observed changes are dispatched to the observer’s object ObserveValue(NSString, NSObject, NSDictionary, IntPtr) method.

(Inherited from NSObject)
AddObserver(NSString, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

(Inherited from NSObject)
AddObserver(String, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

(Inherited from NSObject)
AppendPathComponent(NSString)

Appends the specified str in a manner that results in a path.

AppendPathExtension(NSString)

Creates a path by appending a path extension separator and then the specified str as a file extension.

AppendPaths(String[])

Returns the array of strings created by appending this NSString to each of the specified input paths.

AwakeFromNib()

Called after the object has been loaded from the nib file. Overriders must call base.AwakeFromNib().

(Inherited from NSObject)
BeginInvokeOnMainThread(Action) (Inherited from NSObject)
BeginInvokeOnMainThread(Selector, NSObject)

Invokes asynchrously the specified code on the main UI thread.

(Inherited from NSObject)
Bind(NSString, NSObject, String, NSDictionary) (Inherited from NSObject)
Bind(String, NSObject, String, NSDictionary)
Obsolete.
(Inherited from NSObject)
BindingInfo(String)
Obsolete.
(Inherited from NSObject)
BindingOptionDescriptions(String)
Obsolete.
(Inherited from NSObject)
BindingValueClass(String)
Obsolete.
(Inherited from NSObject)
BoundingRectWithSize(CGSize, NSStringDrawingOptions, NSDictionary)
Capitalize(NSLocale)

Capitalizes a string using the rules of the specified locale.

CommitEditing() (Inherited from NSObject)
CommitEditing(NSObject, Selector, IntPtr) (Inherited from NSObject)
CommonPrefix(NSString, NSStringCompareOptions)
Compare(NSString)

Lexically compares this to the specified string.

Compare(NSString, NSStringCompareOptions)
Compare(NSString, NSStringCompareOptions, NSRange)
Compare(NSString, NSStringCompareOptions, NSRange, NSLocale)
ConformsToProtocol(IntPtr)

Invoked to determine if this object implements the specified protocol.

(Inherited from NSObject)
Contains(NSString)
Copy()

Performs a copy of the underlying Objective-C object.

(Inherited from NSObject)
Copy(NSZone)

Performs a copy of the underlying Objective-C object.

CreateNative(String)

Creates an Objective-C NSString from the C# string and returns a pointer to it.

CreateNative(String, Boolean)
CreateNative(String, Int32, Int32)
CreateNative(String, Int32, Int32, Boolean)
DangerousAutorelease() (Inherited from NSObject)
DangerousRelease() (Inherited from NSObject)
DangerousRetain() (Inherited from NSObject)
DeleteLastPathComponent()

Returns a new string by deleting the last path component of this string.

DeletePathExtension()

Returns a new string by deleting the path extension from this string.

DetectStringEncoding(NSData, EncodingDetectionOptions, String, Boolean)
DetectStringEncoding(NSData, NSDictionary, String, Boolean)
DidChange(NSKeyValueChange, NSIndexSet, NSString)

Indicates a change occurred to the indexes for a to-many relationship.

(Inherited from NSObject)
DidChange(NSString, NSKeyValueSetMutationKind, NSSet) (Inherited from NSObject)
DidChangeValue(String)

Indicates that a change occurred on the specified key.

(Inherited from NSObject)
Dispose()

Releases the resources used by the NSObject object.

(Inherited from NSObject)
Dispose(Boolean)

Releases the resources used by the NSObject object.

(Inherited from NSObject)
DoesNotRecognizeSelector(Selector)

Indicates that this object does not recognize the specified selector.

(Inherited from NSObject)
DrawString(CGPoint, NSDictionary)
DrawString(CGRect, NSDictionary)
DrawString(CGRect, NSStringDrawingOptions, NSDictionary)
Encode(NSStringEncoding, Boolean)
EncodeTo(NSCoder)

Encodes the state of the object on the provided encoder

Equals(NSObject) (Inherited from NSObject)
Equals(NSString, NSString)
Equals(Object)
ExpandTildeInPath()

Returns a new string that expands a tilde in this string (indicating the user's home dir) into a full path.

ExposedBindings() (Inherited from NSObject)
FromData(NSData, NSStringEncoding)

Creates an NSString from an NSData source.

FromHandle(IntPtr)

Utility method that returns a string from a pointer that points to an Objective-C NSString object.

GetBindingInfo(NSString) (Inherited from NSObject)
GetBindingOptionDescriptions(NSString) (Inherited from NSObject)
GetBindingValueClass(NSString) (Inherited from NSObject)
GetDictionaryOfValuesFromKeys(NSString[])

Retrieves the values of the specified keys.

(Inherited from NSObject)
GetHashCode()

Generates a hash code for the current instance.

GetItemProviderVisibilityForTypeIdentifier(String)
GetLineStart(nuint, nuint, nuint, NSRange)
GetLocalizedUserNotificationString(NSString, NSObject[])
GetLocalizedUserNotificationString(String, NSObject[])
GetMethodForSelector(Selector) (Inherited from NSObject)
GetNativeField(String)
Obsolete.
(Inherited from NSObject)
GetNativeHash() (Inherited from NSObject)
GetObject(NSData, String, NSError)
GetParagraphPositions(nuint, nuint, nuint, NSRange)
GetParagraphRange(NSRange)
GetPasteboardPropertyListForType(String)
GetReadableTypesForPasteboard(NSPasteboard)
GetReadingOptionsForType(String, NSPasteboard)
GetVariantFittingPresentationWidth(nint)
GetWritableTypesForPasteboard(NSPasteboard)
GetWritingOptionsForType(String, NSPasteboard)
HasPrefix(NSString)
HasSuffix(NSString)
Init() (Inherited from NSObject)
InitializeHandle(IntPtr) (Inherited from NSObject)
InitializeHandle(IntPtr, String) (Inherited from NSObject)
InitWithPasteboardPropertyList(NSObject, String)
Invoke(Action, Double) (Inherited from NSObject)
Invoke(Action, TimeSpan) (Inherited from NSObject)
InvokeOnMainThread(Action) (Inherited from NSObject)
InvokeOnMainThread(Selector, NSObject)

Invokes synchrously the specified code on the main UI thread.

(Inherited from NSObject)
IsEqual(NSObject) (Inherited from NSObject)
IsEqualTo(IntPtr)
IsKindOfClass(Class) (Inherited from NSObject)
IsMemberOfClass(Class) (Inherited from NSObject)
LineRangeForRange(NSRange)
LoadData(String, Action<NSData,NSError>)

Implement this method to customize the loading of data by an NSItemProvider.

LoadDataAsync(String)
LoadDataAsync(String, NSProgress)
LocalizedCaseInsensitiveContains(NSString)
LocalizedFormat(NSString, NSObject[])
LocalizedFormat(NSString, Object[])
LocalizedFormat(String, Object[])
LocalizedStandardContainsString(NSString)
LocalizedStandardRangeOfString(NSString)
MarkDirty()

Promotes a regular peer object (IsDirectBinding is true) into a toggleref object.

(Inherited from NSObject)
MutableCopy()

Creates a mutable copy of the specified NSObject.

(Inherited from NSObject)
MutableCopy(NSZone)

Performs a copy of the underlying Objective-C object.

ObjectDidEndEditing(NSObject) (Inherited from NSObject)
ObserveValue(NSString, NSObject, NSDictionary, IntPtr)

Indicates that the value at the specified keyPath relative to this object has changed.

(Inherited from NSObject)
PathWithComponents(String[])

Constructs a path from the specified array of components.

PerformSelector(Selector) (Inherited from NSObject)
PerformSelector(Selector, NSObject) (Inherited from NSObject)
PerformSelector(Selector, NSObject, Double)

Invokes the selector on the current instance and if the obj is not null, it passes this as its single parameter.

(Inherited from NSObject)
PerformSelector(Selector, NSObject, Double, NSString[]) (Inherited from NSObject)
PerformSelector(Selector, NSObject, NSObject) (Inherited from NSObject)
PerformSelector(Selector, NSThread, NSObject, Boolean) (Inherited from NSObject)
PerformSelector(Selector, NSThread, NSObject, Boolean, NSString[]) (Inherited from NSObject)
PrepareForInterfaceBuilder() (Inherited from NSObject)
ReleaseNative(IntPtr)

Releases a native Objective-C string.

RemoveObserver(NSObject, NSString)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath.

(Inherited from NSObject)
RemoveObserver(NSObject, NSString, IntPtr)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath and context.

(Inherited from NSObject)
RemoveObserver(NSObject, String)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath.

(Inherited from NSObject)
RemoveObserver(NSObject, String, IntPtr)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath and context.

(Inherited from NSObject)
Replace(NSRange, NSString)

Returns a new string that substitutes the replacement string into this string, at the specified range.

ResolveSymlinksInPath()

Resolves all symbolic links in this and returns the standardized path result.

RespondsToSelector(Selector)

Whether this object recognizes the specified selector.

(Inherited from NSObject)
SeparateComponents(NSCharacterSet)
SeparateComponents(NSString)
SetNativeField(String, NSObject)
Obsolete.
(Inherited from NSObject)
SetNilValueForKey(NSString)

Sets the value of the specified key to null.

(Inherited from NSObject)
SetValueForKey(NSObject, NSString)

Sets the value of the property specified by the key to the specified value.

(Inherited from NSObject)
SetValueForKeyPath(IntPtr, NSString)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

(Inherited from NSObject)
SetValueForKeyPath(NSObject, NSString)

Sets the value of a property that can be reached using a keypath.

(Inherited from NSObject)
SetValueForUndefinedKey(NSObject, NSString)

Indicates an attempt to write a value to an undefined key. If not overridden, raises an NSUndefinedKeyException.

(Inherited from NSObject)
SetValuesForKeysWithDictionary(NSDictionary)

Sets the values of this NSObject to those in the specified dictionary.

(Inherited from NSObject)
StandarizePath()

Standardizes this string into a path by, for instance, removing "/./" and similar constructs.

StringSize(NSDictionary)
ToLower(NSLocale)

Returns a new string that is the lowercase version of this string, according to the rules of the specified locale.

ToString()

Returns a string representation of the value of the current instance.

ToUpper(NSLocale)

Returns a new string that is the uppercase version of this string, according to the rules of the specified locale.

TransliterateString(NSString, Boolean)
TransliterateString(NSStringTransform, Boolean)
Unbind(NSString) (Inherited from NSObject)
Unbind(String)
Obsolete.
(Inherited from NSObject)
ValueForKey(NSString)

Returns the value of the property associated with the specified key.

(Inherited from NSObject)
ValueForKeyPath(NSString)

Returns the value of a property that can be reached using a keypath.

(Inherited from NSObject)
ValueForUndefinedKey(NSString)

Indicates an attempt to read a value of an undefined key. If not overridden, raises an NSUndefinedKeyException.

(Inherited from NSObject)
WillChange(NSKeyValueChange, NSIndexSet, NSString)

Indicates that the values of the specified indices in the specified key are about to change.

(Inherited from NSObject)
WillChange(NSString, NSKeyValueSetMutationKind, NSSet) (Inherited from NSObject)
WillChangeValue(String)

Indicates that the value of the specified key is about to change.

(Inherited from NSObject)

Operators

Equality(NSString, NSString)
Explicit(String to NSString)
Implicit(NSString to String)

Converts the NSString to a CIL/C# string.

Inequality(NSString, NSString)

Extension Methods

DrawString(NSString, CGRect, NSStringDrawingOptions, NSStringAttributes, NSStringDrawingContext)
GetBoundingRect(NSString, CGSize, NSStringDrawingOptions, NSStringAttributes, NSStringDrawingContext)
WeakDrawString(NSString, CGRect, NSStringDrawingOptions, NSDictionary, NSStringDrawingContext)
WeakGetBoundingRect(NSString, CGSize, NSStringDrawingOptions, NSDictionary, NSStringDrawingContext)
ObjectDidBeginEditing(NSObject, INSEditor)
ObjectDidEndEditing(NSObject, INSEditor)
GetValidModes(NSObject, NSFontPanel)
ValidateToolbarItem(NSObject, NSToolbarItem)
GetPasteboardPropertyListForType(INSPasteboardWriting, String)
GetWritableTypesForPasteboard(INSPasteboardWriting, NSPasteboard)
GetWritingOptionsForType(INSPasteboardWriting, String, NSPasteboard)
DrawAtPoint(NSString, CGPoint, NSStringAttributes)
DrawAtPoint(NSString, CGPoint, NSDictionary)
DrawInRect(NSString, CGRect, NSStringAttributes)
DrawInRect(NSString, CGRect, NSDictionary)
StringSize(NSString, NSStringAttributes)
StringSize(NSString, NSDictionary)
GetItemProviderVisibilityForTypeIdentifier(INSItemProviderWriting, String)
GetWritableTypeIdentifiersForItemProvider(INSItemProviderWriting)
LoadDataAsync(INSItemProviderWriting, String)
LoadDataAsync(INSItemProviderWriting, String, NSProgress)
EnumerateLinguisticTags(NSString, NSRange, NSLinguisticTagScheme, NSLinguisticTaggerOptions, NSOrthography, NSEnumerateLinguisticTagsEnumerator)
EnumerateLinguisticTags(NSString, NSRange, NSString, NSLinguisticTaggerOptions, NSOrthography, NSEnumerateLinguisticTagsEnumerator)
GetLinguisticTags(NSString, NSRange, NSLinguisticTagScheme, NSLinguisticTaggerOptions, NSOrthography, NSValue[])
GetLinguisticTags(NSString, NSRange, NSString, NSLinguisticTaggerOptions, NSOrthography, NSValue[])
GetDebugDescription(INSObjectProtocol)
CreateStringByAddingPercentEncoding(NSString, NSCharacterSet)
CreateStringByAddingPercentEscapes(NSString, NSStringEncoding)
CreateStringByRemovingPercentEncoding(NSString)
CreateStringByReplacingPercentEscapes(NSString, NSStringEncoding)
AcceptsPreviewPanelControl(NSObject, QLPreviewPanel)
BeginPreviewPanelControl(NSObject, QLPreviewPanel)
EndPreviewPanelControl(NSObject, QLPreviewPanel)
DrawString(NSString, CGRect, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)
GetBoundingRect(NSString, CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)
WeakDrawString(NSString, CGRect, NSStringDrawingOptions, NSDictionary, NSStringDrawingContext)
WeakGetBoundingRect(NSString, CGSize, NSStringDrawingOptions, NSDictionary, NSStringDrawingContext)
GetAccessibilityCustomRotors(NSObject)

Gets the array of UIAccessibilityCustomRotor objects appropriate for this object.

SetAccessibilityCustomRotors(NSObject, UIAccessibilityCustomRotor[])

Sets the array of UIAccessibilityCustomRotor objects appropriate for this object.

DrawString(NSString, CGPoint, UIStringAttributes)
DrawString(NSString, CGRect, UIStringAttributes)
GetSizeUsingAttributes(NSString, UIStringAttributes)

The SizeF of the string, if rendered with the specified attributes.

WeakDrawString(NSString, CGPoint, NSDictionary)
WeakDrawString(NSString, CGRect, NSDictionary)
WeakGetSizeUsingAttributes(NSString, NSDictionary)

Returns the size of the rendered string.

DrawString(NSString, CGPoint, nfloat, UIFont, nfloat, nfloat, UILineBreakMode, UIBaselineAdjustment)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method.

DrawString(NSString, CGPoint, nfloat, UIFont, nfloat, UILineBreakMode, UIBaselineAdjustment)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method.

DrawString(NSString, CGPoint, nfloat, UIFont, UILineBreakMode)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method..

DrawString(NSString, CGPoint, UIFont)

Developers should not use this deprecated method. Developers should use 'NSString.DrawString (CGPoint, UIStringAttributes)' instead.

DrawString(NSString, CGRect, UIFont)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method.

DrawString(NSString, CGRect, UIFont, UILineBreakMode)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method.

DrawString(NSString, CGRect, UIFont, UILineBreakMode, UITextAlignment)

Developers should use M:Foundation.NSString.DrawString(CoreGraphics.CGRect, UIKit.UIStringAttributes) rather than this deprecated method.

StringSize(NSString, UIFont)

Developers should use GetSizeUsingAttributes(NSString, UIStringAttributes) rather than this deprecated method.

StringSize(NSString, UIFont, CGSize)

The calculated size of the string if rendered with the font or constrainedToSize, whichever is smaller.

StringSize(NSString, UIFont, CGSize, UILineBreakMode)

Gets the CGSize necessary to display this NSString.

StringSize(NSString, UIFont, nfloat, nfloat, nfloat, UILineBreakMode)

Gets the CGSize necessary to display this NSString.

StringSize(NSString, UIFont, nfloat, UILineBreakMode)

Gets the CGSize necessary to display this NSString.

Applies to

See also