In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the knowledge points related to js intercepting strings". In the daily operation, I believe many people have doubts about the knowledge points related to js intercepting strings. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions about "what are the knowledge points related to js intercepting strings?" Next, please follow the editor to study!
Intercept numbers in a string
1. Use parseInt ()
Var str = "4500 yuan"; var num = parseInt (str); console.log (num); / / 4500parseInt () method parameter can have a non-numeric string, as long as the number precedes the string
2. Use regularities
Var str = "Price 4500 CNY"; var num= s.replace (/ [^ 0-9] / ig, ""); alert (num); / / 4500web frontend development learning Q-q-u-n: 784783012, sharing development tools, zero basics, advanced video tutorials, hoping beginners take fewer detours to intercept strings
1. Use split ()
/ / function: use the specified delimiter to cut the string and store it in the array var str = "a force brecediccrecy"; var arr= str.split (","); console.log (arr); / / ["a", "b", "c", "d", "e", "f"]
2. Use join ()
/ / function: combine a number into a string var arr= using the delimiter you specify. Var str= arr.join ("|"); console.log (str); / / "a | c | d | e | f"
3. Use substring ()
/ / function: you can intercept specified fields var str= "abcdef"; var str2= str.substring (0Magne3); console.log (str2); / / "abcd"
4. Use indexOf ()
/ function: returns the subscript var str= "hello web" of the first character in the string that matches the substring; var S1 = str.indexOf ("ll"); / / 2var S2 = str.indexOf ("j"); / / returns-1 if there is no match
5. Use substr ()
/ / function: returns a string var str= "hello web" of specified length starting from the specified position; var S1 = str.substr (0Power4); / / hellvar S2 = str.substr (3); / / "lo web" so far, the study of "what are the knowledge points related to the interception of strings by js" is over, hoping to solve your 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.