Due to the need to intercept strings in the project,Then hand disabled used the substr automatically suggested by ide. I didn't think so much that substr and substring were not much different.
But it ’s not,Listen to me one by one.
1. substr (index, length)
Extracts a specified number of characters from a string from the starting index number.
The substr method can pass two parameters, index and length. index is the starting bit,length is the truncated length.
When index is a non-negative integer:
a. If no parameters are passed in,What you get is the string itself.
Example:"abcdefg" .substr ()->"abcdefg"
b. If only one parameter is passed,That is, the index is intercepted to the last bit of the string by default.
For example:"abcdefg" .substr (2)->"defg".
When index is a negative integer:
c. If a negative integer subscript bit is passed in, it counts from back to front,The starting bit is 1, the subscript bit that reaches the absolute value of the negative integer,The interception was from after.
Example:"abcdefg" .substr (-2)->"fg"<=>"abcdefg" .substr (-2 + "abcdefg" .length)
2. substring (start, end)
Extracts characters in a string between two specified indices.
substring is also passed two parameters,But these two parameters are subscript numbers,The subscript is calculated from 0,The intercepted length is the difference between these two subscripts
Can be recorded as "with head and no tail"
Example:"abcdefg" .substring (2,4)->"cd"
- 3 ways to implement substring in js
- Analysis of the methods of substring and substr in js
- Detailed usage of substr, substring, indexOf, lastIndexOf, split, replace in js
- JS implementation of C # 's StringBuilder effect complete example
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file