string Class

string Class — A series of characters. This isn't really a class, as suggested by its lower-case name. Parameters of type string pass by value, unlike all variables of real object types, which pass by reference. Instead, this is just a pseudo-class which provides convenience methods on instances of strings. The other pseudo-class is int.

Methods

compare(string s) : int

Compare one string with another. Returns a negative number if n is alphabetically before the subject, positive if greater or zero if the two are equal. Note that this function currently does a simple ASCII compare, not a proper unicode-aware sort.

contains(string sub) : bool

Return true if string contains $sub

css_keyword() : string

If the string is syntactically valid as a CSS keyword (only letters and spaces) returns it, else returns an empty string.

css_keyword(string[] allowed) : string

Same as string.css_keyword() except also imposes a whitelist of valid keywords given in $allowed.

css_keyword_list() : string

Analyses the string as a space-separated list of CSS keywords and returns a string containing the items that are syntactically acceptable.

css_keyword_list(string[] allowed) : string

Same as string.css_keyword_list() except also imposes a whitelist of valid keywords given in $allowed.

css_length_value() : string

If the string contains a valid CSS length value, returns a canonical version. Else returns an empty string.

css_string() : string

Returns the string escaped and quoted as a CSS string literal, safe for insertion into a stylesheet.

css_url_value() : string

If the string contains a valid HTTP or HTTPS URL it is returned. Otherwise, an empty string is returned.

ends_with(string sub) : bool

Returns true if string ends in $sub

length() : int

Return the number of characters in the string.

lower() : string

Returns string in lower case.

repeat(int n) : string

Returns the string repeated n times

starts_with(string sub) : bool

Returns true if string begins with $sub

substr(int start, int length) : string

Returns up to $length characters from string, skipping $start characters from the beginning.

upper() : string

Returns string in upper case

upperfirst() : string

Return string with the first character capitalized.