Monthly Archives: November 2009

19 Javascript String functions explained

1. escape(string):
The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as “%20.”
Use unescape() function to get back the original string.

2. unescape(string):
De-encodes a string that is encoded using escape() function.

3. encodeURI(string):
The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: “:”, “/”, “;”, and “?”. Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.

4. decodeURI(string):
De-encodes a string that is encoded using encodeURI() function.

5. charAt(n):
Returns the character at the position nth position.

6. charCodeAt(n):
Returns the encoded character at the nth position.

7. concat(string):
Returns a concatenated string.

8. String.fromCharCode(numX,numX,…,numX):
Returns a string created from Unicode values.

9. stringObject.indexOf(searchvalue,fromindex):
Returns the position of of a specified string value’s first occurrence in a string.

10. stringObject.lastIndexOf(searchvalue,fromindex):
Returns the position of of a specified string value’s last occurrence in a string.

11. stringObject.match(regexp):
Searches for a specified value in a string.

12. stringObject.replace(regexp/substr,newstring):
Replaces some characters with some other characters in a string.

13. stringObject.search(regexp):
Searches a string for a specified value.

14. stringObject.slice(begin,end):
Extracts a part of a string and returns the extracted part in a new string.

15. stringObject.split(separator, limit):
Splits a string into an array of strings.

16. stringObject.substr(start, length):
Extracts a specified number of characters in a string, from a start index.

17. stringObject.substring(indexA, indexB):
Extracts the characters in a string between two specified indices.

18. stringObject.toLowerCase():
Converts to Lower Case string.

19. stringObject.toUpperCase()
Converts to Upper Case string.

Advertisements