当前位置:网站首页>[JS] intercepting string

[JS] intercepting string

2022-06-21 06:38:00 Boyun V

JS Intercepting string

The first one is :SubString

grammar :

start: The starting position of the string to be intercepted ( from 0 Start )

end: At the end of the intercept

 character string .substring(start,end)    

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EOCp7xhJ-1655712281113)(../../../images/image-20220620151640845.png)]

Example :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-4wHydei3-1655712281114)(../../../images/image-20220620151406333.png)]

The second kind :SubStr

grammar :

from: From which position to start intercepting ( from 0 Start counting )

length: How long is the interception limit ( Default : Interception from from All characters from position to end )

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-BWKtdvdp-1655712281115)(../../../images/image-20220620151834477.png)]

 Such as :"20220620RS28204".substr(8)
 Output results :==>'RS28204'

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-OPgGiUbX-1655712281115)(../../../images/image-20220620152301980.png)]

The third kind of :Slice[ Recommended ]

As shown in the figure below : and substring It's about the same , But more than its function More powerful !!=== Can use attachments

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ktT4tMbo-1655712281116)(../../../images/image-20220620152411447.png)]

Add :

Can extract a part of a string , And return the extracted part with a new string .

stringObject.slice(start,end)

start : The starting subscript of the fragment to be extracted . If it's a negative number , This parameter specifies the position from the end of the string . in other words ,

-1 : The last character of a string ,-2 Refers to the penultimate character , And so on .

end : The subscript at the end of the segment to be extracted .

​ If this parameter is not specified , The substring to be extracted includes start String to the end of the original string .

​ If the parameter is negative , So it specifies the position from the end of the string .

原网站

版权声明
本文为[Boyun V]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210628349752.html