Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does js intercept the part of a string between specified characters

Shulou Source: shulou.com Published: 2022-05-31 10:38:26 09月22日 Update

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.

Tags: Characters strings parts methods between knowledge family examples industry grammar different practical beautiful subscript two content practicality practical home article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB NVidia OPPO Reno MySQL