How does js intercept the part of a string between specified characters
This article mainly introduces the relevant knowledge of "how js intercepts the part between specified characters in a string". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to intercept the part between specified characters in a string by js" can help you solve the problem.
Method 1: use the slice () method
You can extract a part of a string and return the extracted part as a new string.
Grammar
String.slice (start,end)
Example
Var str= "abc12345"; alert (str.slice (3)) / / = > 12345 truncate the first three characters and retain the last few characters
Method 2: use the substring () method
Used to extract characters that are mediated between two specified subscripts.
Grammar
String.substring (start,stop)
Example
Var disName = 'Happy Family Beautiful Home'; var shortName = disName.substring (0P5); console.log (shortName); / / print result: happy clan drifting on "how to intercept the part between specified characters in a string by js" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.