"String" Standard Type
String is the shared name used by Elements on all platforms and languages for the type used to represent character strings. In Elements, strings are
immutable by-reference types (classes) that contain a sequence of Unicode Char
s, accessible via a 0-based default indexer using the square brackets ([]
) operator.
Strings are Objects, so string references can be nil
/null
, or they can contain a value of 0 or more characters. There is no maximum length for strings, except of course as constrained by memory. Since Strings are objects, the string implementation on each platform provides numerous methods and properties on the String type that can be used to work with strings.
In C#, the string
keyword can also be used to refer to this type.
Literals
In all languages, double quotes ("..."
) can be used to define string literals.
In Oxygene, string literals can also be defined using single quotes ('...'
) for strings of zero length or a length of 2 or more. (Single-quote literals with a single character are considered Char
literals, but may be treated as strings depending on context.)
Type Mappings
- On .NET,
String
maps to theSystem.String
FCL class. - On Cocoa,
String
maps to theNSString
class provided by the SDKs. - On Java,
String
maps to thejava.lang.String
JDK class. - On Island,
String
is implemented in Island RTL asRemObjects.Elements.System.String
.
There is also a RemObjects.Elements.RTL.String
type defined by Elements RTL for use in code that is shared across platforms. It maps to each platform's native string, but provides a more consistent API.
And the Swift Base Library defines additional extensions on the platform's String types that make it more consistent across platforms and with Swift's String type.
Finally, Users porting Delphi code can use RemObjects.Elements.RTL.Delphi.DelphiString
type defined by the Delphi RTL compatibility library. This mapping behaves more compatible with Delphi's string type, including support for mutability, and optional 1-based indexing.
Per-Object-Model Strings on Island.
On Island, a String
type is declared for each Object Model (where applicable).
Short | Long | Real Type |
---|---|---|
IslandString | RemObjects.Elements.System.Island.String | RemObjects.Elements.System.String |
CocoaString | RemObjects.Elements.System.Cocoa.String | Foundation.NSString |
SwiftString | RemObjects.Elements.System.Swift.String | Swift.String |
DelphiString | RemObjects.Elements.System.Delphi.String | RemObjects.Elements.System.DelphiString |
The short form "String" (and in C# the string
keyword) will always refer to the one matching the Default object model set for the project. This is achieved by the compiler putting the RemObjects.Elements.System.<DefaultObjectModel>
namespace in scope.