Instance Analysis of ES6 string
This article mainly explains the "ES6 string example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "ES6 string example analysis" bar!
1. Two new methods have been added
(1) startWith: determine whether a string begins with a field
Let str='asdfgh';console.log (str.startsWith ('a')); / / true
Application:
Let str=' http://it.kaikeba.com'; If (str.startsWith ('http://')){ console.log)} else if (str.startsWith (' https://')){ console.log)} else if (str.startsWith ('git://')) {console.log ("git URL")} else if (str.startsWith (' svn://')) {console.log ("svn URL")} else { Console.log ("other URLs")}
(2) endsWith: determine whether a string ends with a field
By the same token:
Let str='asdfg.txt';if (str.endsWith ('.txt')) {console.log ("text file")} else if (str.endsWith ('.png')) {console.log ("png picture")} else if (str.endsWith ('.jpg')) {console.log ("jpg picture")} else {console.log ("other files")}
2. String template, string concatenation
(1) stuff something directly into the string
Let str1='asdfgh';// the first string method let str2='asdfgh';// the second string mode let str3= `asdfgh`; / / the third way: anti-single quotation marks / application: let axiom 12 let str4= `a ${a} bc`; console.log (str4); / / a12bc
(2) can be folded
Let title=' title'; let content=' content'; let str1='\'+ title+'\
'+ content+'
\'; let str2= `$ {title}
${content}
Thank you for your reading. the above is the content of "ES6 string instance Analysis". After the study of this article, I believe you have a deeper understanding of the problem of ES6 string instance analysis, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!