Strings (javascript)

From HalfgeekKB
Revision as of 16:44, 10 May 2005 by 161.253.9.181 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

charAt

str.charAt(2)

Returns a single-character string.

charCodeAt

str.charCodeAt(2)

Returns an int value.

fromCharCode

String.fromCharCode(65,66,67,68,69)

Returns a string made up of the list of codes.

indexOf

str.indexOf('a')
str.indexOf('a',2)

The "after" index is optional. Returns -1 if nothing is found.


lastIndexOf

str.lastIndexOf('a')

Like indexOf.


length

str.length

This is a property, not a function.

split

array = str.split("/")

Returns an array.

substring

str.substring(beforeIndex,afterIndex)

Includes beforeIndex, excludes afterIndex. afterIndex is optional, assumes the end of the string.

substr

str.substr(beforeIndex,length)

Length is optional. substring is more compatible.

toLowerCase

str.toLowerCase()

toUpperCase

str.toUpperCase()