|
The way to deconstruct and manipulate text strings. AKA parsing.
myString.charAt(n)
Returns the character at the "n" location in the string, counting from 0
myString.charCodeAt(n)
Returns a number that represents the unicode character code at the "n" location in the string
Unicode includes more characters than can be displayed on some computers
link http://www.unicode.org/ standard/WhatIsUnicode.html)
Currently 236,029 characters
myString.concat(thisString, thatString, ... anyNumberOfStrings)
Combines the text of two strings and returns a new string. Similar to +
myString. romCharCode(c1,c2,...cN)
Returns a string made up of the characters specified in the parameters. Can be a useful way to dynamically create strings that use unusual characters.
myString.indexOf(test,[startPoint])
Searches the string and returns the index of the substring specified in the parameters. This is the way to search for a word in a string, but is especially useful to find if a word is not in a string, which returns -1.
myString="This sentence is about Harry"
if (myString.indexOf("Fred") == -1) {
trace("Fred isn't in the sentence");
}
myString.lastIndexOf(test,[startPoint])
Returns the index of the last substring within the string that appears before the start position specified in the parameter, or -1 if not found.
myString.slice(startPosition, [endPosition])
Extracts a section of a string and returns a new string.
myString = "lexington"
Traces as: "ex"
myString.split("delimiter", [limit])
Splits a string into an array of strings by separating the string into substrings. Most useful when "delimiter" is a space. Optional limit is the number of items placed into the array (not the element numbers).
myString="This sentence is about Harry"
myString.split(" ")
Traces as: "This,sentence,is,about,Harry"
myString.split("", 6) //empty string and limit
Traces as: "T,h,i,s, ,s"
myString.substr(start, length)
Returns a specified number of characters in a string beginning at the location specified in the parameter. Useful to break out words from a longer string.
myString="This sentence is about Harry"
myString.substr(5,8)
Traces as: "sentence"
myString.substring(start, finish)
Like .substr(), but goes from start to finish locations, not start to length. To get the same result as above with myString:
myString.substring(5,13)
String.toLowerCase()
Converts the string to lowercase and returns the result; does not change the contents of the original object. Useful for testing the content of a string without worrying about capitalization. Same myString as above.
myString.indexOf("harry")
Traces as: "-1"
lcString = myString.toLowerCase
lcString.indexOf("harry")
Traces as: "23"
String.toUpperCase()
Obvious, I hope.
String.length
Returns the length of the string.
|