Common APIs-String functions, API strings
:
var myString = new String(“Every good boy does fine.”);var myString = “Every good boy does fine.”;
var myString = “Every ” + “good boy ” + “does fine.”;var myString = “Every “; myString += “good boy does fine.”;
// Capture the character var myString = "Every good boy does fine. "; var section = myString. substring (6); // Result: "good boy does fine. "// truncate the character var myString =" Every good boy does fine starting from 0th to 10th. "; var section = myString. substring (11th); // Result: "Every good" // capture the character var myString = "Every good boy does fine from the second to the last 6th characters. "; var section = myString. slice (11,-6); // result: "boy does" // The 4-character var myString = "Every good boy does fine. "; var section = myString. substr (6, 4); // Result: "good"
Var myString = "Hello"; var lcString = myString. toLowerCase (); // Result: "hello" var ucString = myString. toUpperCase (); // Result: "HELLO"
Var aString = "Hello !"; Var bString = new String ("Hello !"); If (aString = "Hello !" ) {}// Result: trueif (aString = bString) {}// result: false (two objects are different, although their values are the same)
Var myString = "hello everybody. "; // if the string cannot be retrieved,-1 is returned. if (myString. indexOf ("every")>-1) {} // result: true
- Search for replacement strings
Var myString = "I is your father."; var result = myString. replace ("is", "am"); // result: "I am your father ."
Special characters
\b
: Return character
\t
: Horizontal Tab
\n
: Line Break
\v
: Vertical Tab
\f
: Paging character
\r
: Carriage Return
\”
: Double quotation marks
\’
: Single quotes
\ Reverse oblique Rod
- Convert characters
Unicode
Encoding
Var myString = "hello"; var code = myString. charCodeAt (3); // returns the Unicode (integer) var char = String of "l. fromCharCode (66); // returns the Unicode 66 character
- Convert string to URL Encoding
Var myString = "hello all"; var code = encodeURI (myString); // Result: "hello % 20all" var str = decodeURI (code); // result: "hello all" // corresponding to: encodeURIComponent () decodeURIComponent ()
Text/poetries (simplified author)
Link: http://www.jianshu.com/p/1f2314552e23