String
Stores mutable (garbage collected), UTF-16 strings. String maps to JavaScript String object. Strings can be delimited by a single quote ('abc') or double quote ("ABC").
Explicit Unicode characters can be specified by using # followed by an integer codepoint (decimal or hexadecimal). Characters specified this way are always understood as Unicode codepoint.
Following statement would output 'Hello' followed by CR+LF (ASCII code 13 and 10), followed by
'World'.
writeln('Hello'#13#$0D'World');
In a single-quoted string, a single quote can be expressed by doubling it ('can''quote this!'). In a double-quoted string, a double-quote can be expressed by doubling it ("A""QUOTE"). Double-quoted strings can span multiple lines.
This is an equivalent of the example few lines above.
writeln("Hello
World");
Strings can also be defined with #" or #'. In this case the compiler will then ignore common indentation, and will additionally ignore an empty first line. Following example is equivalent to both examples above.
writeln(#"
Hello
World");
The String type has built-in Low/High/Length pseudo-methods, similar to those of the array types. You can use str.Low, str.High and str.Length as an alternative to Low(str), High(str) & Length(str).
[1.1.2] In operator can be used to check for substrings (if 'java' in 'javascript' then).
[1.1.2] Helpers can operate directly on string constants ("Smart".Reverse).
Methods
Informations
Length () : Integer
Low () : Integer
High () : Integer
Testing
Contains (subStr : String) : Boolean
StartsWith (beginStr : String) : Boolean
EndsWith (endStr : String) : Boolean
EqualsText (str2 : String) : Boolean
Case conversions
UpperCase () : String // ASCII upper case
LowerCase () : String // ASCII lower case
ToLower () : String // locale lower case
ToUpper () : String // locale upper case
Conversions
ToBoolean () : Boolean
ToFloat () : Float
ToFloatDef (def : Float) : Float
ToInteger () : Integer
ToIntegerDef (def : Integer) : Integer
Manipulations
After (delimiter : String) : String // returns characters after a delimiter
Before (delimiter : String) : String // returns characters before a delimiter
CompareText (str2 : String) : Integer
CompareTo (str2 : String) : Integer
DeleteLeft (count : Integer) : String // delete N characters to the left
DeleteRight (count : Integer) : String // delete N characters to the right
Dupe (count : Integer) : String // duplicate the string N times
Format (args : array of const ) : String
HexToInteger () :Integer
Left (count : Integer) : String // return N characters to the left
LeftStr(str:string; count:Integer) // takes a certain portion of the left side of a string.
Matches (mask : String) : Boolean
MidStr(str:string; start:Integer; count:Integer) // takes a specified number of characters from a string.
QuotedString (quoteChar : String = '') : String
Replace (sub : String; newSub : String) : String
Reverse () : String // returns a version of the string with the character reversed
Right (count : Integer) : String // return N characters to the right
RigthStr(str:string; count:Integer) // takes a certain portion of the right side of a string.
Split (delimiter : String) : array of string // split a string on a separator and returns an array of strings
Trim (str : String) : String // trim control characters left & right
Trim (nbLeft : Integer; nbRight : Integer) : String // trim control characters left & right
TrimLeft () : String // trim left control characters
TrimRight () : String // trim right control characters
Internal String functions
This section hasn't been formatted yet and is a copy-paste from the dwsStringFunctions.pas source.
· | _(str : String) : invokes the localizer on the specified string (GNU GetText like) |
· | Chr(i : Integer) : returns the string corresponding to the given Unicode codepoint (supports the whole Unicode range) |
· | IntToStr(i : Integer) : returns a string representing i in decimal notation |
· | StrToInt(str : String) : returns the conversion the passed string to a number |
· | StrToIntDef(str : String, def: Integer) : returns the conversion the passed string to a number |
· | VarToIntDef(val : Variant; def : Integer) : |
· | IntToHex (v : Integer; digits : Integer) : |
· | HexToInt (hexa : String]) : |
· | IntToBin (v : Integer; digits : Integer) : |
· | BoolToStr (b : Boolean) : |
· | StrToBool (str : String) : |
· | FloatToStr (f : Float; p : Integer = 99) : |
· | StrToFloat (str : String) : |
· | StrToFloatDef (str : String; def : Float) : |
· | VarToFloatDef (val : Variant; def : Float) : |
· | Format (fmt : String; args : array of const) : |
· | CharAt (s : String; x : Integer) : |
· | Delete (s : String; index : Integer; Len : Integer) : |
· | Insert (src : String; s : String; index : Integer]) : |
· | LowerCase (str : String) : |
· | AnsiLowerCase (str : String) : |
· | UpperCase (str : String) : |
· | AnsiUpperCase (str : String) : |
· | Pos (subStr : String; str : String) : |
· | PosEx (subStr : String; str : String; offset : Integer) : |
· | RevPos (subStr : String; str : String) : |
· | SetLength (S : String; NewLength : Integer): |
· | TrimLeft (str : String) : |
· | TrimRight (str : String) : |
· | SameText (str1 : String; str2 : String) : |
· | CompareText (str1 : String; str2 : String) : |
· | AnsiCompareText (str1 : String; str2 : String) : |
· | CompareStr (str1 : String; str2 : String) : |
· | AnsiCompareStr (str1 : String; str2 : String) : |
· | IsDelimiter (delims : String; str : String; index : Integer) : |
· | LastDelimiter (delims : String; str : String) : |
· | FindDelimiter (delims : String; str : String; startIndex : Integer = 1) : |
· | QuotedStr (str : String; quoteChar : String) : |
· | Copy (str : String; index : Integer; Len : Integer) : |
· | LeftStr (str : String; count : Integer) : |
· | RightStr (str : String; count : Integer) : |
· | MidStr (str : String; start : Integer; count : Integer) : |
· | SubStr (str : String; start : Integer) : |
· | SubString (str : String; start : Integer; end : Integer) : |
· | StringOfChar (ch : String; count : Integer) : |
· | StringOfString (str : String; count : Integer) : |
· | DupeString (str : String; count : Integer) : |
· | StrBeginsWith (str : String; beginStr : String) : |
· | StrEndsWith (str : String; endStr : String) : |
· | StrAfter (str : String; delimiter : String) : |
· | StrBefore (str : String; delimiter : String) : |
· | StrReplace(str, sub, newSub : String) : returns a string where all occurences of sub in str are replace by newSub |
· | StrSplit(str, delimiter : String) : returns the string splitted on the delimiters as an array of string |
· | StrJoin(strs : array of string; delimiter : String) : joins the strings in the array, concatenating them with delimiter in between each item and returns the resulting string |
· | RegisterInternalIntFunction(TStrToIntFunc, 'StrToInt', ['str', cString], iffStateLess); |
· | RegisterInternalIntFunction(TStrToIntDefFunc, 'StrToIntDef', ['str', cString, 'def', cInteger], iffStateLess); |
· | RegisterInternalIntFunction(TStrToIntDefFunc, 'VarToIntDef', ['val', cVariant, 'def', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TIntToHexFunc, 'IntToHex', ['v', cInteger, 'digits', cInteger], iffStateLess); |
· | RegisterInternalIntFunction(THexToIntFunc, 'HexToInt', ['hexa', cString], iffStateLess); |
· | RegisterInternalStringFunction(TIntToBinFunc, 'IntToBin', ['v', cInteger, 'digits', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TBoolToStrFunc, 'BoolToStr', ['b', cBoolean], iffStateLess); |
· | RegisterInternalStringFunction(TFloatToStrFunc, 'FloatToStr', ['f', cFloat, 'p=99', cInteger], iffStateLess); |
· | RegisterInternalFloatFunction(TStrToFloatFunc, 'StrToFloat', ['str', cString], iffStateLess); |
· | RegisterInternalFloatFunction(TStrToFloatDefFunc, 'StrToFloatDef', ['str', cString, 'def', cFloat], iffStateLess); |
· | RegisterInternalFloatFunction(TStrToFloatDefFunc, 'VarToFloatDef', ['val', cVariant, 'def', cFloat], iffStateLess); |
· | RegisterInternalStringFunction(TFormatFunc, 'Format', ['fmt', cString, 'args', 'array of const'], iffStateLess); |
· | RegisterInternalStringFunction(TCharAtFunc, 'CharAt', ['s', cString, 'x', cInteger], iffStateLess); |
· | RegisterInternalFunction(TDeleteFunc, 'Delete', ['@S', cString, 'index', cInteger, 'Len', cInteger], ''); |
· | RegisterInternalFunction(TInsertFunc, 'Insert', ['src', cString, '@S', cString, 'index', cInteger], ''); |
· | RegisterInternalStringFunction(TLowerCaseFunc, 'LowerCase', ['str', cString]); |
· | RegisterInternalStringFunction(TAnsiLowerCaseFunc, 'AnsiLowerCase', ['str', cString]); |
· | RegisterInternalStringFunction(TUpperCaseFunc, 'UpperCase', ['str', cString]); |
· | RegisterInternalStringFunction(TAnsiUpperCaseFunc, 'AnsiUpperCase', ['str', cString]); |
· | RegisterInternalIntFunction(TPosFunc, 'Pos', ['subStr', cString, 'str', cString], iffStateLess); |
· | RegisterInternalIntFunction(TPosExFunc, 'PosEx', ['subStr', cString, 'str', cString, 'offset', cInteger], iffStateLess); |
· | RegisterInternalIntFunction(TRevPosFunc, 'RevPos', ['subStr', cString, 'str', cString], iffStateLess); |
· | RegisterInternalFunction(TSetLengthFunc, 'SetLength', ['@S', cString, 'NewLength', cInteger], ''); |
· | RegisterInternalStringFunction(TTrimLeftFunc, 'TrimLeft', ['str', cString], iffStateLess); |
· | RegisterInternalStringFunction(TTrimRightFunc, 'TrimRight', ['str', cString], iffStateLess); |
· | RegisterInternalStringFunction(TTrimFunc, 'Trim', ['str', cString], iffStateLess); |
· | RegisterInternalBoolFunction(TSameTextFunc, 'SameText', ['str1', cString, 'str2', cString], iffStateLess); |
· | RegisterInternalIntFunction(TCompareTextFunc, 'CompareText', ['str1', cString, 'str2', cString], iffStateLess); |
· | RegisterInternalIntFunction(TAnsiCompareTextFunc, 'AnsiCompareText', ['str1', cString, 'str2', cString], iffStateLess); |
· | RegisterInternalIntFunction(TCompareStrFunc, 'CompareStr', ['str1', cString, 'str2', cString], iffStateLess); |
· | RegisterInternalIntFunction(TAnsiCompareStrFunc, 'AnsiCompareStr', ['str1', cString, 'str2', cString], iffStateLess); |
· | RegisterInternalBoolFunction(TIsDelimiterFunc, 'IsDelimiter', ['delims', cString, 'str', cString, 'index', cInteger], iffStateLess); |
· | RegisterInternalIntFunction(TLastDelimiterFunc, 'LastDelimiter', ['delims', cString, 'str', cString], iffStateLess); |
· | RegisterInternalIntFunction(TFindDelimiterFunc, 'FindDelimiter', ['delims', cString, 'str', cString, 'startIndex=1', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TQuotedStrFunc, 'QuotedStr', ['str', cString, 'quoteChar=', cString], iffStateLess); |
· | RegisterInternalStringFunction(TCopyFunc, 'Copy', ['str', cString, 'index', cInteger, 'Len', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TLeftStrFunc, 'LeftStr', ['str', cString, 'count', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TRightStrFunc, 'RightStr', ['str', cString, 'count', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TCopyFunc, 'MidStr', ['str', cString, 'start', cInteger, 'count', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TSubStrFunc, 'SubStr', ['str', cString, 'start', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TSubStringFunc, 'SubString', ['str', cString, 'start', cInteger, 'end', cInteger], iffStateLess); |
· | RegisterInternalStringFunction(TStringOfCharFunc, 'StringOfChar', ['ch', cString, 'count', cInteger], ); |
· | RegisterInternalStringFunction(TStringOfStringFunc, 'StringOfString', ['str', cString, 'count', cInteger], ); |
· | RegisterInternalStringFunction(TStringOfStringFunc, 'DupeString', ['str', cString, 'count', cInteger], ); |
· | RegisterInternalBoolFunction(TStrBeginsWithFunc, 'StrBeginsWith', ['str', cString, 'beginStr', cString], iffStateLess); |
· | RegisterInternalBoolFunction(TStrEndsWithFunc, 'StrEndsWith', ['str', cString, 'endStr', cString], iffStateLess); |
· | RegisterInternalStringFunction(TStrAfterFunc, 'StrAfter', ['str', cString, 'delimiter', cString], iffStateLess); |
· | RegisterInternalStringFunction(TStrBeforeFunc, 'StrBefore', ['str', cString, 'delimiter', cString], iffStateLess); |
· | StrReplace(str, sub, newSub : String) : returns a string where all occurences of sub in str are replace by newSub |
· | StrSplit(str, delimiter : String) : returns the string splitted on the delimiters as an array of string |
· | StrJoin(strs : array of string; delimiter : String) : joins the strings in the array, concatenating them with delimiter in between each item and returns the resulting string |
· | ReverseString(str : String) : returns a string that is a reversed version of str |
Go to String object JS reference.
|