Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete substrings by es6

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of es6 how to delete the substring, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this es6 article on how to delete the substring. Let's take a look at it.

There are two ways to delete substrings: 1, use replace () to remove the substrings that appear for the first time in the string, syntax "string object .replace (" substring value ",") "; 2, use replaceAll () to remove all substrings, syntax" string object .replaceAll ("substring value", ")".

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

The method of deleting substring in es6

1. Use the replace () function

The replace () method is used to replace substrings of other characters in a string with some characters.

The specified substring can be deleted when the replacement value is a null character.

Var str = "Hello world!"; var n=str.replace ("Hello", ""); console.log (n)

The replace () function replaces only the substrings that match for the first time:

Var str= "Visit Microsoft! Visit Microsoft!"; var n=str.replace ("Microsoft", ""); console.log (n)

2. Use the replaceAll () function

The replaceAll () method is used to replace some characters in a string with other characters, or to replace a substring that matches a regular expression, which replaces all matching substrings.

Similarly, the specified substring can be deleted when the replacement value is a null character.

Var str = "Hello world!"; var n=str.replaceAll ("world", ""); console.log (n)

The replaceAll () function replaces all matching substrings:

Var str= "Visit Microsoft! Visit Microsoft!"; var n=str.replaceAll ("Microsoft", ""); console.log (n)

This is the end of the article on "how to delete substrings in es6". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to delete substrings in es6". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report