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 intercept specified content in js string

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "how the js string intercepts the specified content". In the daily operation, I believe that many people have doubts about how to intercept the specified content in the js string. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to intercept the specified content in the js string". Next, please follow the editor to study!

Method 1: use the slice () method to segment and intercept the specified string and store it in an array

Extracts a part of the string with the specified start and end positions and returns the extracted part as a new string.

Var a = "i am a boy"; var b=a.slice (0recom 6); / / "i am a"

Method 2: use the substring () method to intercept the specified string

Used to extract characters that are mediated between two specified subscripts.

Var str = 'abcdefghij';console.log (' (1,2):'+ str.substring (1,2)); / /'(1,2): b'console.log ('(1,1):'+ str.substring (1,1)); / /'(1,1):'

Method 3: use the substr () method to intercept the specified string

Returns a substring of the specified length starting at the specified location.

Var str = 'abcdefghij';console.log (' (1,2):'+ str.substr (1,2)); / /'(1,2): bc'console.log ('(- 3,2):'+ str.substr (- 3,2)); / /'(- 3,2): hi' ends the study of "how js strings intercept specified content", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Internet Technology

Wechat

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

12
Report