The substring () method in Java has overloads of two methods, one with one parameter and one with two parameters.
The first one is written as: substring (n);//start interception from the character of the index is n, the condition (n>=0,n< string length), and the index of the initial character is 0. N as the first argument, must be less than the length of the string, because this side is from the beginning of containing n intercept, so n must not be equal to the length of the string, and the bottom of the m as the second parameter can be equal.
The second way: substring (n,m);//start with N, intercept m-n characters, condition (n<m,m<= string length)
Popular point:
str.substring (int begin,int end); From the beginning of the string (the starting position is the subscript, the subscript is starting from 0) to intercept to the end position, contains before, not included!
String sql = "ABCDEFG";
String a = sql.substring (0,4);
System.out.println (a);
Result: ABCD
Subscript starting from 0
Below is a comparison of MySQL string interception rules:
Common MySQL intercept functions are: Left (), right (), substring (), Substring_index ()
Here are one by one instructions:
1. Left intercept (str, length)
Description: Left (truncated field, intercept length)
That is, the long length character is truncated from the leftmost edge of the STR string.
2. Right intercept (str, length)
Description: Right (truncated field, intercept length)
That is, the long length character is truncated from the far right of the STR string.
3.substring (str, POS); SUBSTRING (str, POS, len)
Description: Substring (intercepted field, starting from the first intercept) substring (intercepted field, intercept from the first, intercept length)
The string that does not have the Len argument starts at the point of POS (the number of POS bits refers to the entire string consisting of several characters, that is, the number of letters. That is, POS is starting from 1 and not 0, which is different from the subscript (starting from 0) intercept rule in the Java Intercept function substring (). and the corresponding character that contains this digit begins the interception. If the POS is a negative number, it means to start from the right to the left of the POS single-digit number of characters, and then intercept, and then intercept to the last; the Len parameter starts with the number of POS digits and intercepts the Len length (from the POS position as the first start number).
4.substring_index (Str,delim,count)
Description: Substring_index (the number of occurrences of the intercepted field, keywords, keywords), if "The number of occurrences of the keyword" is positive, such as a, indicating that the string is truncated from the leftmost point, until the first keyword. If the number of occurrences of a keyword is negative, such as negative A, it indicates that the string is truncated from the far right until it starts at right-to-left, and at the first keyword.
Java string intercept-finally with MySQL string intercept comparison