String Class
Text string.
Item Index
Methods
Properties
Methods
charAt
index
Get character on index position.
Parameters:
-
index
IntegerZero-based index
Returns:
charCodeAt
index
Returns (Uni)code of character at index position.
Parameters:
-
index
IntegerZero-based index
Returns:
concat
[string1]
Creates string consisting from concatenated arguments: self + string1 + string2 + string3 + ... + stringN.
Parameters:
-
[string1]
Integer optional multipleZero-based index of first character.
Returns:
Example:
var str = "moscrif";
str.concat(" is").concat(" the best SDK"); // returns "moscrif is the best SDK"
endWith
str
Determines whether the start of this string instance matches the specified string.
Parameters:
-
str
StringThe string to compare.
Returns:
fromCharCode
[code1]
Creates string build from character with given integer codes.
Parameters:
-
[code1]
Integer optional multipleInteger codes of characters
Returns:
htmlEscape
() String
Replace each < > & " or ' character by < > & " or ' sequence.
Returns:
htmlUnescape
() String
Restores html-escape string.
Returns:
indexOf
substring
[start]
Searches this string for text in substring.
Parameters:
Returns:
lastIndexOf
substring
[start]
Searches this string for text in substring.
Parameters:
Returns:
localeCompare
what
Compares this string with what string using lexicographic character order.
Parameters:
-
what
StringString to compare
Returns:
Example:
var str = "b";
str.localeCompare("a"); // returns 1
str.localeCompare("b"); // returns 0
str.localeCompare("c"); // returns -1
match
regexp|str
Returns fragment(s) of the string which satisfy regexp or returns RegExp object instance which satisfy string pattern.
printf
format
[value1]
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 < sequences in the output.[/li]
Parameters:
-
format
StringString specifying format of text
-
[value1]
Object optional multipleValues to be inserted to text
Returns:
replace
regexp
replaceBy
Replaces all fragments satisfying regexp by replaceBy.
Parameters:
Returns:
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
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
StringString specifying format of text
Returns:
search
regexp
Returns index of first occurence of string fragment satisfying regexp or -1 if not found.
Parameters:
-
regexp
RegExpRegular expression
Returns:
split
regexp|str
[limit]
Splits the string separated on components by separator.
Parameters:
Returns:
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 < words.length; i++) {
console<<words[i]<<"\n";
}
startsWith
str
Determines whether the beginning of this string instance matches the specified string.
Parameters:
-
str
StringThe string to compare.
Returns:
substr
start
[length]
Creates string beginning by start index with required length.
Parameters:
Returns:
Example:
var str = "moscrif";
str.substr(2,3); // scr
substring
start
[end]
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:
Returns:
Example:
var str = "moscrif";
str.substring(1, 3); // os
str.substring(0,-3); // moscr
toFloat
defaultValue=undefined
Tries to parse content of the string. If parsing failed then returns defaultValue if provided, or undefined value.
Parameters:
-
defaultValue=undefined
FloatValue, which is returned when parsing failed
Returns:
toHtmlString
() String
Returns string escaped by html rules. Is an alias of the htmlEscape() method.
Returns:
toInteger
defaultValue=undefined
Tries to parse content of the string. If parsing failed then returns defaultValue if provided, or undefined value.
Parameters:
-
defaultValue=undefined
IntegerValue, which is returned when parsing failed.
Returns:
Example:
//toInteger expects string in the following format:
[whitespace] [{+ | -}] [0 [{ x | X }]] [digits][/code]
toLowerCase
() String
Creates lower case copy of the string.
Returns:
Example:
var string = "Moscrif";
console<<string.toLowerCase()<<"\n"; // moscrif
toNumber
defaultValue=undefined
Tries to parse the string into either float or integer value.
Returns:
Example:
//This is an equivalent of:
var n = s.toInteger(s.toFloat());
toSymbol
() Symbol
Returns string itself.
Returns:
toUpperCase
() String
Creates upper case copy of the string.
Returns:
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:
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