출처 : http://srufaculty.sru.edu/david.dailey/javascript/string.html
string handling mechanisms
The basics
Fancier stuff
| string.split(re) splits a string into an array, based on a delimiter (a string or regular expression) If s="a.bc.def.g.hijk" and re="." |
delim index |
string |
|
Using join and split to replace substrings (like sed 's/alpha/beta/g' in UNIX) | ||
|
Using the replace method, with regular expressions: var r=/[aeiou]/g //a regular expression for all vowels. Then, s.replace(r,"Q") returns "hQppy QvQr QftQr Qn the mQrkQtplQcQ" | ||
|
string.match(re) If string="Do it and think." and re=/[^\s]*t\s+/ |
re= | string= |
| string.match(re) | ||
|
Dealing with keystrokes | ||
Specialized things
| eval(string) converts string of digits (or an expression) to number Useful for reading form elements on a page (which by default are read as strings). if string="12345" then eval(string)=12345. |
string |
| eval(string) | |
| eval(numberstring).toString(16) converts number to hexadecimal if numberstring=255 |
number |
number.toString(16) | |
| Numeric to ASCII |
number |
String.fromCharCode(number) | |
| ASCII to Numeric |
ASCIIchar |
| number=ASCIIchar.charCodeAt(0) | |
| escape(string) replaces special characters by escape sequences |
|
escape(string) |









