Javascript Strings
Line 5: | Line 5: | ||
* <div id="length">'''length'''</div> | * <div id="length">'''length'''</div> | ||
Property that describes the length of a string as a decimal number. | Property that describes the length of a string as a decimal number. | ||
+ | |||
+ | Returns numeric length of string | ||
+ | |||
+ | x="abcd"; | ||
+ | Engine.output(x.length); | ||
+ | |||
+ | '''4''' | ||
* <div id="charAt">'''charAt(pos)'''<div> | * <div id="charAt">'''charAt(pos)'''<div> | ||
− | Function that returns a character at a certain position in string. | + | Function that returns a character at a certain 0-based position in string. |
+ | |||
+ | Returns a string containing a single character or empty if ''pos'' is out of bounds. | ||
+ | |||
+ | x="abcd"; | ||
+ | Engine.output(x.charAt(3)); | ||
+ | |||
+ | '''d''' | ||
* <div id="indexOf">'''indexOf(str)'''</div> | * <div id="indexOf">'''indexOf(str)'''</div> | ||
Function that returns the position of a substring in another string. | Function that returns the position of a substring in another string. | ||
+ | |||
+ | Returns 0-based position of ''str'' or -1 if str is not found | ||
+ | |||
+ | x="abcd"; | ||
+ | Engine.output(x.indexOf("bc")); | ||
+ | |||
+ | '''1''' | ||
* <div id="substr">'''substr(offs,len)'''</div> | * <div id="substr">'''substr(offs,len)'''</div> | ||
Function that returns a substring. | Function that returns a substring. | ||
+ | |||
+ | Returns a string that starts at 0-based position ''offs'' and has at most ''len'' characters | ||
+ | |||
+ | x="abcd"; | ||
+ | Engine.output(x.substr(1,2)); | ||
+ | |||
+ | '''bc''' | ||
* '''substr(offs)''' | * '''substr(offs)''' | ||
Function that returns a substring. | Function that returns a substring. | ||
+ | |||
+ | Returns a string that starts at 0-based position ''offs'' to the end of the original string | ||
+ | |||
+ | x="abcd"; | ||
+ | Engine.output(x.substr(2)); | ||
+ | |||
+ | '''cd''' | ||
* <div id="match">'''match(reg)'''</div> | * <div id="match">'''match(reg)'''</div> |
Revision as of 17:09, 10 September 2013
Although the String object is not directly supported by Yate's Javascript these methods are applicable to most non-object variables.
Note that these are not real properties of strings and cannot be enumerated!
- length
Property that describes the length of a string as a decimal number.
Returns numeric length of string
x="abcd"; Engine.output(x.length); 4
- charAt(pos)
Function that returns a character at a certain 0-based position in string.
Returns a string containing a single character or empty if pos is out of bounds.
x="abcd"; Engine.output(x.charAt(3)); d
- indexOf(str)
Function that returns the position of a substring in another string.
Returns 0-based position of str or -1 if str is not found
x="abcd"; Engine.output(x.indexOf("bc")); 1
- substr(offs,len)
Function that returns a substring.
Returns a string that starts at 0-based position offs and has at most len characters
x="abcd"; Engine.output(x.substr(1,2)); bc
- substr(offs)
Function that returns a substring.
Returns a string that starts at 0-based position offs to the end of the original string
x="abcd"; Engine.output(x.substr(2)); cd
- match(reg)
Function that matches a string against a Regular Expression.
- toLowerCase()
Function that converts a string to lower case.
- toUpperCase()
Function that converts a string to upper case.
- trim()
Function that removes leading and trailing spaces from a string.
- sqlEscape()
Function that performs SQL escaping on a string.
- startsWith(str)
Function that checks if a string starts with a specific substring.
- endsWith(str)
Function that checks if a string ends with a specific substring.
- split(sep)
Function that splits a string into an Array at a separator.
- toString()
Function that converts a number to string using numbering base 10.
- toString(base)
-