The interception of strings is a very small method that is often used in development, but because many local indexes are easily confused by the 0/1 contention. Record a few of the known uses.
- The substring () method in Java
(1) xx.substring (int begin) intercepts the content starting at the specified position to the end of the character.
(2) xx.substring (int begin,int end) intercepts the character content between the specified start index and the end index. ( the intercepted content contains begin does not contain end)
Note : Begin is starting at 0. The number that is intercepted when the character is intercepted .
① if the value of start and end is equal, an empty string is returned.
② if the setting is begin set to a negative number will be error java.lang.StringIndexOutOfBoundsException:String in Dex out of Range:xx
- SUBSTRING () method in SQL Server database
(1)SUBSTRING (expression,begin,length ) intercepts the length of a character starting at the specified position. (intercept contains begin position)
Note : Begin is starting at 1 . If the begin is set to 0 then the truncated result will be one less than the length setting, which is equivalent to intercepting the length-1, and begin allows for a negative value to be set.
- Oracle Database substr () method
(1) substr (string, Begin, [ length ]) intercepts the length of the character starting at the specified position, and the length of the setting can be selected. If the value of length is not specified, all content after the start of begin is intercepted.
If a negative number is intercepted from behind, 1 refers to the last character in the string, 2 refers to the second-to-penultimate character, and so on.
Note:begin is starting at 1. Begin, whether set to 0 or 1, is intercepted from the first character, which is separated from the substring area in SQL Server and allowed to be set to a negative number.
- The substr () method in JavaScript
(1) xx.substr (start,length) Start is the starting subscript for the extracted character, the index of start starting from 0, intercept characters of length.
If a negative number is intercepted from behind, 1 refers to the last character in the string, 2 refers to the second-to-penultimate character, and so on.
Note:the index of start starts at 0 and is allowed to be set to a negative number.
(1) xx.substring (start,end) Start is the starting subscript of the extracted character, starting at index 0, and its contents are all characters from start to stop-1. (contains start does not contain end)
Note: The following three points are more special, you need to pay attention to.
① If the value of start and end is equal, an empty string is returned.
② If start is larger than end, the method will exchange the two parameters before extracting the substring.
③ If start or end is negative, it will be replaced with 0.
Truncate string Partial Summary