String

Moduleejs
Namespaceintrinsic
Definitionfinal class String
InheritanceString inherit Object

Each String object represents a single immutable linear sequence of characters.

Strings have operators for: comparison, concatenation, copying, searching, conversion, matching, replacement, and, subsetting.


Properties

QualifiersPropertyTypeDescription
No properties defined

String Methods

QualifiersMethod
public %(obj: Object): String
 Format arguments as a string.
public -(str: String): String
 String subtraction.
public caseCompare(compare: String): Number
 Do a case sensitive comparison between this string and another.
public charAt(index: Number): String
 Return the character at a given position in the string.
public charCodeAt(index: Number): Number
 Get a character code.
public concat(args: Array): String
 Concatenate strings and returns a new string.
public contains(pattern: Object): Boolean
 Check if a string contains a pattern.
public endsWith(test: String): Boolean
 Determine if this string ends with a given string.
public format(args: Array): String
 Format arguments as a string.
public static fromCharCode(codes: Array): String
 Create a string from the character code arguments.
iterator override get(deep: Boolean): Iterator
 Get an iterator for this array to be used by "for (v in string)".
iterator override getValues(deep: Boolean): Iterator
 Get an iterator for this array to be used by "for each (v in string)".
public indexOf(pattern: String, startIndex: Number): Number
 Search for an item using strict equality "===".
public get isAlpha(): Boolean
 If there is at least one character in the string and all characters are alphabetic return true.
public get isDigit(): Boolean
 If there is at least one character in the string and all characters are digits return true.
public get isLower(): Boolean
 If there is at least one character in the string that can be upper or lower case and all characters are lower case return true.
public get isSpace(): Boolean
 If there is at least one character in the string and all characters are white space return true.
public get isUpper(): Boolean
 If there is at least one character in the string that can be upper or lower case and all characters are upper case return true.
public lastIndexOf(pattern: String, location: Number): Number
 Search right to left for a substring starting at a given index.
public override get length(): Number
 Get the length of a string.
public match(pattern: RegExp): Array
 Match the a regular expression pattern against a string.
public parseJSON(filter: Function): Object
 Parse the current string object as a JSON string object.
public printable(): String
 Create a new string with all nonprintable characters replaced with unicode hexadecimal equivalents (e.
public quote(): String
 Wrap a string in double quotes.
public remove(start: Number, end: Number): String
 Remove characters from a string.
public replace(pattern: Object, replacement: String): String
 Search and replace.
public reverse(): String
 Reverse a string.
public search(pattern: Object): Number
 Search for a pattern.
public slice(start: Number, end: Number, step: Number): String
 Extract a substring.
public split(delimiter: Object, limit: Number): Array
 Split a string into an array of substrings.
public startsWith(test: String): Boolean
 Tests if this string starts with the string specified in the argument.
String(str: Array)
 String constructor.
public substring(startIndex: Number, end: Number): String
 Extract a substring.
public times(times: Number): String
 Replication.
public toCamel(): String
 Copy the string into a new string and lower case the first letter if there is one.
public override toJSON(): String
 Convert the string to an equivalent JSON encoding.
public tokenize(format: String): Array
 Scan the input and tokenize according to a string format specifier.
public toLower(locale: String): String
 Convert the string to lower case.
public toPascal(): String
 Copy the string into a new string and capitalize the first letter if there is one.
public override toString(locale: String): String
 This function converts an object to a string representation.
public toUpper(locale: String): String
 Convert the string to upper case.
public trim(str: String): String
 Returns a trimmed copy of the string.

Method Detail

public %(obj: Object): String

Format arguments as a string.

Description
Use the string as a format specifier.
Parameters
Returns
-1 if less than, zero if equal and 1 if greater than.
Specified
Ejs-11.
Example
"%5.3f" % num
"Arg1 %d, arg2 %d" % [1, 2]

public -(str: String): String

String subtraction.

Description
Remove the first occurance of str.
Parameters
str: String The string to remove from this string
Returns
Return a new string.
Specified
Ejs-11.

public caseCompare(compare: String): Number

Do a case sensitive comparison between this string and another.

Parameters
Returns
-1 if less than, zero if equal and 1 if greater than.
Specified
Ejs-11.

public charAt(index: Number): String

Return the character at a given position in the string.

Returns
A new string containing the selected character.

Throws

RangeException:


public charCodeAt(index: Number): Number

Get a character code.

Parameters
Returns
Return the character code at the specified index. If the index is -1, get the last character.

Throws

OutOfBoundsError: If the index is less then -1 or greater then or equal to the size of string.


public concat(args: Array): String

Concatenate strings and returns a new string.

Parameters
args: Array Strings to append to this string
Returns
Return a new string.

public contains(pattern: Object): Boolean

Check if a string contains a pattern.

Parameters
pattern: Object The pattern can be either a string or regular expression.
Returns
Returns true if the pattern is found.
Specified
Ejs-11.

public endsWith(test: String): Boolean

Determine if this string ends with a given string.

Parameters
test: String The string to test with
Returns
True if the string matches.
Specified
Ejs-11.

public format(args: Array): String

Format arguments as a string.

Description
Use the string as a format specifier.
Parameters
args: Array Array containing the data to format.
Returns
-1 if less than, zero if equal and 1 if greater than.
Specified
Ejs-11.
Example
"%5.3f".format(num) \n\n "%s Arg1 %d, arg2 %d".format("Hello World", 1, 2)

static public fromCharCode(codes: Array): String

Create a string from the character code arguments.

Parameters
codes: Array Character codes from which to create the string
Returns
A new string.

override iterator get(deep: Boolean): Iterator

Get an iterator for this array to be used by "for (v in string)".

Parameters
deep: Boolean Follow the prototype chain. Not used. [default: false]
Returns
An iterator object.

override iterator getValues(deep: Boolean): Iterator

Get an iterator for this array to be used by "for each (v in string)".

Parameters
deep: Boolean Follow the prototype chain. Not used. [default: false]
Returns
An iterator object.

public indexOf(pattern: String, startIndex: Number): Number

Search for an item using strict equality "===".

Description
This call searches from the start of the string for the specified element.
Parameters
pattern: String The string to search for.
startIndex: Number Where in the array (zero based) to start searching for the object.
Returns
The items index into the array if found, otherwise -1.

Throws

OutOfBoundsError: If the starting index is greater than or equal to the size of the array or less then 0.


get public isAlpha(): Boolean

If there is at least one character in the string and all characters are alphabetic return true.

Returns
False otherwise.
Specified
Ejs-11.

get public isDigit(): Boolean

If there is at least one character in the string and all characters are digits return true.

Returns
False otherwise.
Specified
Ejs-11.

get public isLower(): Boolean

If there is at least one character in the string that can be upper or lower case and all characters are lower case return true.

Returns
False otherwise.
Specified
Ejs-11.

get public isSpace(): Boolean

If there is at least one character in the string and all characters are white space return true.

Returns
False otherwise.
Specified
Ejs-11.

get public isUpper(): Boolean

If there is at least one character in the string that can be upper or lower case and all characters are upper case return true.

Returns
False otherwise.
Specified
Ejs-11.

public lastIndexOf(pattern: String, location: Number): Number

Search right to left for a substring starting at a given index.

Parameters
pattern: String The string to search for
location: Number The integer starting to start the search or a range to search in.
Returns
Return the starting index of the last match found.

Throws

OutOfBoundsError: If the index is less then -1 or greater then or equal to the size of string.


override get public length(): Number

Get the length of a string.

Returns
Return the length of the string in characters.

public match(pattern: RegExp): Array

Match the a regular expression pattern against a string.

Parameters
pattern: RegExp The regular expression to search for
Returns
Returns an array of matching substrings.

public parseJSON(filter: Function): Object

Parse the current string object as a JSON string object.

Description
The.
Parameters
filter: Function Function to call for each element of objects and arrays. Not yet supported
Returns
An object representing the JSON string.

public printable(): String

Create a new string with all nonprintable characters replaced with unicode hexadecimal equivalents (e.

Description
G. \uNNNN).
Returns
The new string.
Specified
Ejs-11.

public quote(): String

Wrap a string in double quotes.

Returns
The new string.

public remove(start: Number, end: Number): String

Remove characters from a string.

Description
Remove the elements from.
Parameters
start: Number Numeric index of the first element to remove. Negative indicies measure from the end of the string. -1 is the last character element.
end: Number Numeric index of one past the last element to remove
Returns
A new string with the characters removed.
Specified
Ejs-11.

public replace(pattern: Object, replacement: String): String

Search and replace.

Description
Search for the given pattern which can be either a string or a regular expression and replace it with the replace text.
Parameters
pattern: Object The regular expression pattern to search for
replacement: String The string to replace the match with or a function to generate the replacement text
Returns
Returns a new string.
Specified
Ejs-11.

public reverse(): String

Reverse a string.

Returns
Returns a new string with the order of all characters reversed.
Specified
Ejs-11.

public search(pattern: Object): Number

Search for a pattern.

Parameters
pattern: Object Regular expression pattern to search for in the string.
Returns
Return the starting index of the pattern in the string.

public slice(start: Number, end: Number, step: Number): String

Extract a substring.

Parameters
start: Number The position of the first character to slice.
end: Number The position one after the last character. Negative indicies are measured from the end of the string.

Throws

OutOfBoundsError: If the range boundaries exceed the string limits.


public split(delimiter: Object, limit: Number): Array

Split a string into an array of substrings.

Description
Tokenizes a string using a specified delimiter.
Parameters
delimiter: Object String or regular expression object separating the tokens.
limit: Number At most limit strings are extracted. If limit is set to -1, then unlimited strings are extracted.
Returns
Returns an array of strings.

public startsWith(test: String): Boolean

Tests if this string starts with the string specified in the argument.

Parameters
test: String String to compare against
Returns
True if it does, false if it doesn't.
Specified
Ejs-11.

String(str: Array)

String constructor.

Description
This can take two forms:
  • String()
  • String(str: String)
Parameters

public substring(startIndex: Number, end: Number): String

Extract a substring.

Description
Similar to slice but only allows positive indicies.
Parameters
startIndex: Number Integer location to start copying
end: Number Postitive index of one past the last character to extract.
Returns
Returns a new string.

Throws

OutOfBoundsError: If the starting index and/or the length exceed the string's limits.


public times(times: Number): String

Replication.

Description
Replicate the string N times.
Parameters
Returns
A new String with the copies concatenated together.
Specified
Ejs-11.

public toCamel(): String

Copy the string into a new string and lower case the first letter if there is one.

Description
If the first non-white character is not a character or if it is already lower there is no change.
Returns
A new String.
Specified
Ejs-11.

override public toJSON(): String

Convert the string to an equivalent JSON encoding.

Returns
A quoted string.

Throws

TypeError: If the object could not be converted to a string.


public tokenize(format: String): Array

Scan the input and tokenize according to a string format specifier.

Parameters
format: String Tokenizing format specifier
Returns
Array containing the tokenized elements.
Specified
Ejs-11.
Example
for (s in string.tokenize("%s %s %s")) { print(s) }

public toLower(locale: String): String

Convert the string to lower case.

Parameters
locale: String
Returns
Returns a new lower case version of the string.
Specified
Ejs-11.

public toPascal(): String

Copy the string into a new string and capitalize the first letter if there is one.

Description
If the first non-white character is not a character or if it is already capitalized there is no change.
Returns
A new String.
Specified
Ejs-11.

override public toString(locale: String): String

This function converts an object to a string representation.

Description
Types typically override this to provide the best string representation.
Parameters
locale: String
Returns
A string representation of the object. For Objects "[object className]" will be returned, where className is set to the name of the class on which the object was based.

public toUpper(locale: String): String

Convert the string to upper case.

Parameters
locale: String
Returns
Returns a new upper case version of the string.
Specified
Ejs-11.

public trim(str: String): String

Returns a trimmed copy of the string.

Description
Normally used to trim white space, but can be used to trim any substring from the start or end of the string.
Parameters
str: String May be set to a substring to trim from the string. If not set, it defaults to any white space.
Returns
Returns a (possibly) modified copy of the string.