Moscrif API Docs for: 2012q3
Show:

String Class

Library: core

Text string.

Methods

$

() String

Returns composed string. Note, this is a "stringizer" method.

Returns:

charAt

(
  • index
)
String

Get character on index position.

Parameters:

Returns:

String: Character one index position. If index is out of bounds of the string then charAt returns empty string.

charCodeAt

(
  • index
)
String

Returns (Uni)code of character at index position.

Parameters:

Returns:

String: (Uni)code of character at index position.

concat

(
  • [string1]
)
String

Creates string consisting from concatenated arguments: self + string1 + string2 + string3 + ... + stringN.

Parameters:

  • [string1] Integer optional multiple

    Zero-based index of first character.

Returns:

String: String consisting from concatenated arguments: self + string1 + string2 + string3 + ... + stringN.

Example:

var str = "moscrif";
str.concat(" is").concat(" the best SDK"); // returns  "moscrif is the best SDK"

endWith

(
  • str
)
Boolean

Determines whether the start of this string instance matches the specified string.

Parameters:

  • str String

    The string to compare.

Returns:

Boolean: True if value matches the ending of this string; otherwise, false.

fromCharCode

(
  • [code1]
)
String

Creates string build from character with given integer codes.

Parameters:

  • [code1] Integer optional multiple

    Integer codes of characters

Returns:

String: String build from character with given integer codes.

htmlEscape

() String

Replace each < > & " or ' character by &lt; &gt; &amp; &quot; or &apos; sequence.

Returns:

htmlUnescape

() String

Restores html-escape string.

Returns:

String: String where html entities replaced by correspondent character codes.

indexOf

(
  • substring
  • [start]
)
Integer

Searches this string for text in substring.

Parameters:

  • substring String

    String to search.

  • [start] Integer optional

    Function starts searching at this position

Returns:

Integer: Index of first occurence of substring or -1 if not found.

lastIndexOf

(
  • substring
  • [start]
)
Integer

Searches this string for text in substring.

Parameters:

  • substring String

    String to search.

  • [start] Integer optional

    Function starts searching at this position

Returns:

Integer: Index of last occurence of substring or -1 if not found.

localeCompare

(
  • what
)
Integer

Compares this string with what string using lexicographic character order.

Parameters:

  • what String

    String to compare

Returns:

Integer: 1;0 or -1 acording to result of comparation

Example:

var str = "b";
str.localeCompare("a"); // returns 1
str.localeCompare("b"); // returns 0
str.localeCompare("c"); // returns -1

match

(
  • regexp|str
)
String | RegExp

Returns fragment(s) of the string which satisfy regexp or returns RegExp object instance which satisfy string pattern.

Parameters:

Returns:

String | RegExp: For given regexp returns fragment(s) of the string which satisfy regexp. For given string returns RegExp object instance which satisfy string pattern.

printf

(
  • format
  • [value1]
)
String

Returns composed string. Note, this is a "stringizer" method. See sprintf C/C++ function Additional format types:

  • %v and %V - these format types accept any value as an argument and produce source code representation of the value suitable for later parsing by eval() method. Thus if value is an array of values it will be printed as [element1, element2, element3... elementN] and object (instance of Object class) will be printed as {key1:value1, key2:value2,..., keyN:valueN}". %v produces one line output and %V tries to produce human readable output with line feeds and tabulations. Use it if you need to serialize objects in AJAX/JSON fashion.[/li]
  • %S - this format type converts its argument into string and outputs it with HTML escapement. So characters like < will be converted to &lt; sequences in the output.[/li]

Parameters:

  • format String

    String specifying format of text

  • [value1] Object optional multiple

    Values to be inserted to text

Returns:

String: Formatted string

replace

(
  • regexp
  • replaceBy
)
String

Replaces all fragments satisfying regexp by replaceBy.

Parameters:

  • regexp RegExp

    Regular expression

  • replaceBy String

    If replaceBy is a function then this function will be called for each matching substring with parameters corresponding to the whole match and each matched sub-group.

Returns:

String: Copy of the string where all fragments satisfying regexp are replaced by replaceBy.

Example:

var s = "25.5K";
// regEsp command, find whole or decimal number and split to two parameters
var regEsp = /(\d+)?(([.])?\d+)/g;
// convert kelvin to celsius
function k2c(str, g, z)
{
    // if number is decimal, z contains decimal part, otherwise it contains last character
    var number = g + z;

    // return converted value
    return (number.toNumber() - 273.15) + "C";
}
// replace value
console<<s.replace(regEsp, k2c )<<"\n";

scanf

(
  • format
)
Array

Scans the string for values according to the rules of sprintf C/C++ function with wildcard (like %[a-z] ) extensions. See definition of scanf in MSDN.aspx). Additional format types:

  • %N - scans for either float or integer number.[/li]

Parameters:

  • format String

    String specifying format of text

Returns:

Array: Function returns array of successfully parsed values.

split

(
  • regexp|str
  • [limit]
)
Array

Splits the string separated on components by separator.

Parameters:

  • regexp|str RegExp | String

    Either regular expression object or string

  • [limit] Integer optional

    Maximum number of elements in returned array

Returns:

Array: Array of strings - substrings between separators.

Example:

var str = "Moscrif is the best cross-platform mobile development tool suite.";
var words = str.split(" ");
// writes list of words from str
for (var i = 0; i &lt; words.length; i++) {
    console&lt;&lt;words[i]&lt;&lt;"\n";
}

startsWith

(
  • str
)
Boolean

Determines whether the beginning of this string instance matches the specified string.

Parameters:

  • str String

    The string to compare.

Returns:

Boolean: True if value matches the beginning of this string; otherwise, false.

substr

(
  • start
  • [length]
)
String

Creates string beginning by start index with required length.

Parameters:

  • start Integer

    Zero-based index of first character.

  • [length] Integer optional

    A number of characters in the slice.

Returns:

String: Required string

Example:

var str = "moscrif";
str.substr(2,3); // scr

substring

(
  • start
  • [end]
)
String

Creates string slice consisting from characters starting from start index and up to but not included end indexes. Note: Negative values of start or end treated as a "right side indexes" thus expression "Script".substring(0,-1) == "Script" is valid.

Parameters:

  • start Integer

    Zero-based index of first character.

  • [end] Integer optional

    Zero-based index of last character. If end is ommited it is interpretted as equal to length.

Returns:

String: String slice consisting from characters starting from start index and up to but not included end index.

Example:

var str = "moscrif";
str.substring(1, 3);    // os
str.substring(0,-3);    // moscr

toFloat

(
  • defaultValue=undefined
)
Float

Tries to parse content of the string. If parsing failed then returns defaultValue if provided, or undefined value.

Parameters:

  • defaultValue=undefined Float

    Value, which is returned when parsing failed

Returns:

Float: Float value parsed from string or undefined / defaultValue if parsing failed

toHtmlString

() String

Returns string escaped by html rules. Is an alias of the htmlEscape() method.

Returns:

toInteger

(
  • defaultValue=undefined
)
Integer

Tries to parse content of the string. If parsing failed then returns defaultValue if provided, or undefined value.

Parameters:

  • defaultValue=undefined Integer

    Value, which is returned when parsing failed.

Returns:

Integer: Integer value parsed from string or undefined / defaultValue if parsing failed.

Example:

//toInteger expects string in the following format:
[whitespace] [{+ | -}] [0 [{ x | X }]] [digits][/code]

toLowerCase

() String

Creates lower case copy of the string.

Returns:

String: Lower case copy of the string.

Example:

var string = "Moscrif";
console<<string.toLowerCase()<<"\n";   // moscrif

toNumber

(
  • defaultValue=undefined
)
Float | Integer

Tries to parse the string into either float or integer value.

Parameters:

  • defaultValue=undefined Float | Integer

    Value, which is returned when parsing failed

Returns:

Float | Integer: Float or integer value parsed from string or undefined / defaultValue if parsing failed.

Example:

    //This is an equivalent of:
    var n = s.toInteger(s.toFloat());

toSymbol

() Symbol

Returns string itself.

Returns:

Symbol:

toUpperCase

() String

Creates upper case copy of the string.

Returns:

String: Upper case copy of the string.

Example:

var string = "Moscrif";
console<<string.toUpperCase()<<"\n";   // MOSCRIF

toUrlString

() String

Returns string escaped by url rules. Is an alias of the urlEscape() method.

Returns:

urlEscape

() String

Creates url-escaped copy of the string if it contains characters need to be escaped or string itself if there are no such characters. Note: that non-ascii characters are converted to utf-8 sequences first and resulting codes will be escaped.

Returns:

String: Url-escaped copy of the string.

urlUnescape

() String

Restores url-escaped string.

Returns:

String: Restored string.

Properties

[begin..end]

Integer

Creates string slice contained characters from start index and up to but not included end index. Zero-based index of first character If begin is ommited then it is assumed to be 0. Zero-based index of last character If end is ommited, length is used as end value. Return string slice contained characters from start index and up to but not included end index.

[index]

Integer

Code of character at the index position, Read-write index accessor. Zero-based index

Example:

var string = "Moscrif";
console<<string[0]<<"\n";       // 111 -> ASCII M
string[0] = 100;                // 100 -> ASCII 100 = d
console<<string<<"\n";          // doscrif

length

Integer

Number of characters in the string.

Example:

var string = "Moscrif";
console<<string.length<<"\n";   // 7