Common APIs-String functions, API strings

Source: Internet
Author: User

Common APIs-String functions, API strings

:

  • Statement
var myString = new String(“Every good boy does fine.”);var myString = “Every good boy does fine.”;

 

  • String connection
var myString = “Every ” + “good boy ” + “does fine.”;var myString = “Every “; myString += “good boy does fine.”;

 

  • Truncate string
// 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"

 

  • Case sensitivity
Var myString = "Hello"; var lcString = myString. toLowerCase (); // Result: "hello" var ucString = myString. toUpperCase (); // Result: "HELLO"

 

  • String comparison
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)

 

  • SEARCH strings
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 charactersUnicodeEncoding
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.