Get the App
SLTechnology News&Howtos  ›  Development  › 

Instance Analysis of ES6 string

Shulou Source: shulou.com Published: 2022-06-01 03:30:02 09月22日 Update

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!

Tags: Characters strings web addresses examples case analysis analysis content learning pictures fields files methods applications ordinary things two that is beginning quotation marks ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn macOS Xiaomi OPPO Reno