This class provides advanced methods on Strings. It is ideally used with
using StringToolsand then acts as an extension to theStringclass.If the first argument to any of the methods is null, the result is unspecified.
static winMetaCharacters:Array<Int> = [" ".code, "(".code, ")".code, "%".code, "!".code, "^".code, "\"".code, "<".code, ">".code, "&".code, "|".code, "\n".code, "\r".code, ",".code, ";".code] Character codes of the characters that will be escaped by quoteWinArg(_, true).
static endsWith (s:String, end:String):BoolTells if the string s ends with the string end.
If end is null, the result is unspecified.
If end is the empty String "", the result is true.
static inline fastCodeAt (s:String, index:Int):IntReturns the character code at position index of String s, or an end-of-file indicator at if position equals s.length.
This method is faster than String.charCodeAt() on some platforms, but the result is unspecified if index is negative or greater than s.length.
End of file status can be checked by calling StringTools.isEof() with the returned value as argument.
This operation is not guaranteed to work if s contains the \0 character.
static hex (n:Int, ?digits:Int):StringEncodes n into a hexadecimal representation.
If digits is specified, the resulting String is padded with "0" until its length equals digits.
static htmlEscape (s:String, ?quotes:Bool):StringEscapes HTML special characters of the string s.
The following replacements are made:
& becomes &< becomes <> becomes >If quotes is true, the following characters are also replaced:
" becomes "' becomes 'static htmlUnescape (s:String):StringUnescapes HTML special characters of the string s.
htmlUnescape(htmlEscape(s)) == s
The replacements follow:
& becomes &
< becomes <
> becomes >
" becomes "
' becomes '
static inline isEof (c:Int):Boolstatic isSpace (s:String, pos:Int):BoolTells if the character in the string s at position pos is a space.
A character is considered to be a space character if its character code is 9,10,11,12,13 or 32.
If s is the empty String "", or if pos is not a valid position within s, the result is false.
static lpad (s:String, c:String, l:Int):StringConcatenates c to s until s.length is at least l.
If c is the empty String "" or if l does not exceed s.length, s is returned unchanged.
If c.length is 1, the resulting String length is exactly l.
Otherwise the length may exceed l.
If c is null, the result is unspecified.
static ltrim (s:String):StringRemoves leading space characters of s.
This function internally calls isSpace() to decide which characters to remove.
If s is the empty String "" or consists only of space characters, the result is the empty String "".
static quoteUnixArg (argument:String):StringReturns a String that can be used as a single command line argument on Unix. The input will be quoted, or escaped if necessary.
static quoteWinArg (argument:String, escapeMetaCharacters:Bool):StringReturns a String that can be used as a single command line argument on Windows. The input will be quoted, or escaped if necessary, such that the output will be parsed as a single argument using the rule specified in http://msdn.microsoft.com/en-us/library/ms880421
Examples:
quoteWinArg("abc") == "abc";
quoteWinArg("ab c") == '"ab c"';
static replace (s:String, sub:String, by:String):StringReplace all occurrences of the String sub in the String s by the String by.
If sub is the empty String "", by is inserted after each character of s. If by is also the empty String "", s remains unchanged.
This is a convenience function for s.split(sub).join(by).
If sub or by are null, the result is unspecified.
static rpad (s:String, c:String, l:Int):StringAppends c to s until s.length is at least l.
If c is the empty String "" or if l does not exceed s.length, s is returned unchanged.
If c.length is 1, the resulting String length is exactly l.
Otherwise the length may exceed l.
If c is null, the result is unspecified.
static rtrim (s:String):StringRemoves trailing space characters of s.
This function internally calls isSpace() to decide which characters to remove.
If s is the empty String "" or consists only of space characters, the result is the empty String "".
static startsWith (s:String, start:String):BoolTells if the string s starts with the string start.
If start is null, the result is unspecified.
If start is the empty String "", the result is true.
static trim (s:String):StringRemoves leading and trailing space characters of s.
This is a convenience function for ltrim(rtrim(s)).
static urlDecode (s:String):StringDecode an URL using the standard format.
static urlEncode (s:String):StringEncode an URL by using the standard format.
© 2005–2018 Haxe Foundation
Licensed under a MIT license.
https://api.haxe.org/StringTools.html