iOS Guides | Samples

Foundation.NSString Class

The Foundation String class.

See Also: NSString


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

See Also


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


Namespace: Foundation
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions:

The members of 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.
Creates an NSString from a C# string.
Creates a string from a specified blob of data, using a specific encoding.

Protected Constructors

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.

Public Fields

static readonly

Public Properties

ClassHandleIntPtr. The handle for this class.
IsAbsolutePathBoolean. Whether this is an absolute path.
default property
LastPathComponentNSString. The last path component of this string.
Lengthnint. The number of Unicode characters in this string.
PathComponentsString[]. An array of strings containing, in order, each path component of this string.
PathExtensionNSString. Returns this string's path extension, if it has one.

Public Methods

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.
CreateNative(String) : IntPtr
Creates an Objective-C NSString from the C# string and returns a pointer to it.
CreateNative(String, Boolean) : IntPtr
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.
DetectStringEncoding(NSData, EncodingDetectionOptions, out String, out Boolean) : nuint
DetectStringEncoding(NSData, NSDictionary, out String, out Boolean) : nuint
Encode(NSStringEncoding, Boolean) : NSData
Encodes the state of the object on the provided encoder
Equals(Object) : Boolean
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.
FromData(NSData, NSStringEncoding) : NSString
Creates an NSString from an NSData source.
FromHandle(IntPtr) : String
Utility method that returns a string from a pointer that points to an Objective-C NSString object.
GetHashCode() : Int32
Generates a hash code for the current instance.
GetItemProviderVisibilityForTypeIdentifier(String) : NSItemProviderRepresentationVisibility
GetLineStart(out nuint, out nuint, out nuint, NSRange)
GetLocalizedUserNotificationString(String, NSObject[]) : String
GetObject(NSData, String, out NSError) : NSString
GetParagraphPositions(out nuint, out nuint, out nuint, NSRange)
GetParagraphRange(NSRange) : NSRange
GetVariantFittingPresentationWidth(nint) : NSString
HasPrefix(NSString) : Boolean
HasSuffix(NSString) : Boolean
IsEqualTo(IntPtr) : Boolean
LineRangeForRange(NSRange) : NSRange
LoadData(String, Action<NSData, NSError>) : NSProgress
Implement this method to customize the loading of data by an NSItemProvider.
LoadDataAsync(String) : System.Threading.Tasks.Task<NSData>
LoadDataAsync(String, out NSProgress) : System.Threading.Tasks.Task<NSData>
LocalizedCaseInsensitiveContains(NSString) : Boolean
LocalizedFormat(NSString, NSObject[]) : NSString
LocalizedFormat(NSString, params Object[]) : NSString
LocalizedFormat(String, params Object[]) : NSString
LocalizedStandardContainsString(NSString) : Boolean
LocalizedStandardRangeOfString(NSString) : NSRange
MutableCopy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.
PathWithComponents(String[]) : String[]
Constructs a path from the specified array of components.
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.
ToLower(NSLocale) : String
Returns a new string that is the lowercase version of this string, according to the rules of the specified locale.
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

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