class StringTools

Class Fields

static function hex(n:Int, ?digits:Int): String

Encodes n into a hexadecimal representation.

If digits is specified, the resulting String is padded with "0" until its length equals digits.

static function htmlEscape(s:String, ?quotes:Bool): String

Escapes HTML special characters of the string s.

The following replacements are made:

  • & becomes &
  • < becomes &lt;
  • > becomes &gt;

If quotes is true, the following characters are also replaced:

  • " becomes &quot;
  • ' becomes &#039;

static function isSpace(s:String, pos:Int): Bool

Tells 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 function ltrim(s:String): String

Removes 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 function replace(s:String, sub:String, by:String): String

Replace all occurences 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 function rtrim(s:String): String

Removes 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 function startsWith(s:String, start:String): Bool

Tells 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 function trim(s:String): String

Removes leading and trailing space characters of s.

This is a convenience function for ltrim(rtrim(s)).