Libraries anvil lang string

class string
extends anvil.lang.sequence
The string class represents character strings. String is a sequence of characters.

Constructor
string(object value)
Creates new string from the string representation of given parameter.


Methods

string capitalize()
Capitalizes the first character of all words.

string capitalizeFirst()
Capitalizes first character of first word.

string charAt(int index)
Returns single character from this string.
Parameters index -  Index to string

int charCodeAt(int index)
Returns the character code at the speicified index.
Parameters index -  Index to string

string chop()
Chops all whitespaces
string chop(string suffix)
Chop given suffix
Chops suffix out of string.

int compareToIgnoreCase(string other)
Compares this string and given string, lower- and uppercase characters are considered equal.
Returns -1 if this<other, 0 if this==other, 1 if this>other,

string compress()
Compresses consequtive white space characeters into single space.

object contains(string pattern)
object contains(string pattern, array matches)
object contains(string pattern, list matches)
object contains(pattern pattern)
object contains(pattern pattern, array matches)
boolobjectean contains(pattern pattern, list matches)
Checks if some region of this string matches given regular expression.
Parameters pattern -  Regular expression pattern
Returns Matches or boolean
Throws MalformedPattern -  If pattern is invalid

string decode()
string decode(string characterEncoding)
Decodes URL encoding from this string.

string decodeURI()
string decodeURI(string characterEncoding)
Decodes URI encoding from this string.

string decodeURL()
string decodeURL(string characterEncoding)
Decodes URL encoding from this string.

list divide(string delim)
list divide(string delim, boolean dir)
Divides string to two pieces, using delim as delimiter. Example 1. "foo.bar.foo".divide(".") returns ("foo", "bar.foo") Example 2. "foo.bar.foo".divide("|") returns ("foo.bar.foo", null) Example 3. "foo.bar.fiu".divide(".", true) return ("fiu", "foo.bar")
Parameters delim -  Delimiter character(s)
dir -  Direction (default false), false = from start of the string, true = from end of the string

string eat()
Removes all whitespaces
string eat(string prefix)
Removes given prefix
Removes given prefix out of string.

string encode()
string encode(string characterEncoding)
URL encodes this string.

binary encodeTo(string encoding)
Encodes this string to binary using given character encoding, throws IOError if string cannot be mapped
binary encodeTo(string encoding, binary replacement)
Encodes this string to binary using given character encoding, unmappable characters are replaced with given binary
binary encodeTo(string encoding, string replacement)
Encodes this string to binary using given character encoding, unmappable characters are replaced with given string
binary encodeTo(string encoding, null ignore)
Encodes this string to binary using given character encoding, unmappable characters are ignored.
Throws BadParameter -  if given character encoding is unsupported, or replacement is invalid
IOError -  if some characters are unmappable and no replacement given

string encodeURI()
string encodeURI(string characterEncoding)
URI encodes this string.

string encodeURL()
string encodeURL(string characterEncoding)
URL encodes this string.

boolean endsWith(string suffix)
Checks if this string ends with given suffix.

boolean equalsIgnoreCase(string other)
Checks if this string is equal to given string, lower- and uppercase characters are considered equal
Parameters other -  String to compare with

string escape()
Escapes string using the rules of anvil string literal.

list explode(string delimiters)
list explode(string delimiters, boolean returnEmpty)
Splits this string into regions using given set of delimiter characters.
Parameters delimiters -  Set of delimiter characters
returnEmpty -  If true also empty regions are returned, if omitted or false empty regions are not returned.

iterator find(string pattern)
iterator find(pattern pattern)
Finds all regions from this string mathing given regular expression pattern.
Parameters pattern -  Regular expression pattern
Returns Iterator of strings
Throws MalformedPattern -  If pattern is invalid

binary hexToBinary()
Converts string to binary, assuming that two characters produce one byte: 414243 -> binary(abc)

int indexOf(string needle)
int indexOf(string needle, int fromIndex)
Returns the index within this string of the first occurrence of the specified string.
Parameters needle -  String to search for
fromIndex -  Starting index of search
Returns The index of first occurence, or -1 if it doesn't occur.

int lastIndexOf(string needle)
int lastIndexOf(string needle, int fromIndex)
Returns the index within this string of the last occurrence of the specified string.
Parameters needle -  String to search for
fromIndex -  Starting index of search
Returns The index of last occurence, or -1 if it doesn't occur.

int length()
Returns the length of this string.

object matches(string pattern)
object matches(string pattern, array matches)
object matches(string pattern, list matches)
object matches(pattern pattern)
object matches(pattern pattern, array matches)
object matches(pattern pattern, list matches)
Checks if this (whole) string matches given regular expression.
Parameters pattern -  Regular expression pattern
Returns Matches or boolean
Throws MalformedPattern -  If pattern is invalid

string nl2br()
Convers all line feeds into <br>

string nowrap()
Converts white spaces into &nbsp;.

string pad(int length)
string pad(int length, string padding)
Pads text left or right to field.
Parameters length -  Length of field, positive for right padding, negative for left padding.
padding -  Padding character, default is space.
Returns Given text padded to field

string quote()
Converts all applicable characters with corresponding html entity.

string quoteMeta()
Converts all applicable characters under >127 with corresponding html entity.

string quoteText()
Converts all applicable characters over >127 with corresponding html entity.

string repeat(int amount)
Repeats this string amount times.

string replace(string from, string to)
Replaces all occurences of from into to.
Parameters from -  Regions to replace
to -  Replacement

list split(string pattern)
list split(pattern pattern)
Splits this string using given regular expression pattern as delimiter.
Parameters pattern -  Regular expression pattern
Throws MalformedPattern -  If pattern is invalid

boolean startsWith(string prefix)
Checks if this string starts with given prefix.

string stri()
Removes all tags, comments and processing instructions from string.

string stripHtml()
Removes all tags comments and processing instructions from string. Additionally text content inside <script>, <style> and <head> are removed, exlucing <title>.

string substitute(string pattern, object replacement [, int amount] )
string substitute(pattern pattern, object replacement [, int amount] )
Substitutes all regions from this string matching given regular expression.
Parameters pattern -  Regular expression pattern
replacement -  Either a string or a function: function replacer(list matchedGroups).
amount -  Number of occurences to replace, if omitted, all occurences are substituted.
Throws MalformedPattern -  If pattern is invalid

string substituteFirst(string pattern, string replacement)
string substituteFirst(pattern pattern, string replacement)
string substituteFirst(string pattern, Function replacer)
string substituteFirst(pattern pattern, Function replacer)
Substitutes first region from this string matching given regular expression.
Parameters pattern -  Regular expression pattern
replacement -  Replacement string
replacer -  Replace function: function replacer(list matchedGroups).
Throws MalformedPattern -  If pattern is invalid

string substring(int start)
string substring(int start, int end)
Returns a substring from the given region of this string.
Parameters start -  Starting index, included
end -  Ending index, excluded

string toLower()
Converts all upper case characeters into corresponding lower case characeters.

string toUpper()
Converts all lower case characeters into corresponding upper case characeters.

string translate(string from, string to)
For each character in this string: if character appears in from string, converts it to character at the same index at to.
Parameters from -  Source character mapping
to -  Target character mapping
Returns Translated string

string trim()
Removes whitespace characters from the beginning and end of this string.

string trimLeft()
Removes whitespace characters from the beginning this string.

string trimRight()
Removes whitespace characters from the end this string.

string unescape()
Unescapes backslash quotes.

string unquote()
Unquotes all html entities from this string.

object unserialize()
Unserializes data contained in this string.
Returns Unserialized data
Throws CorruptedSerialization -  If serialized data is corrupted

string wmlquote()
Converts all applicable characters with corresponding html entity.

string wmlquoteText()
Converts all applicable characters over >127 with corresponding html entity.