SubString() of String in Java

substring:

public String substring(int beginIndex)-returns a string, a substring of this string. The substring extends from the character at the specified index to the end of the string.

public String substring(int beginIndex, int endIndex )——returns a string substring, the range is
[beginIndex, endIndex-1]. The length of such a substring is endIndex-beginIndex.

Special cases:
1. Return an empty string: System.out.println(str.substring(1,1));
2. The starting bit of the string starts from 0, if any parameter of the substring() method is less than 0, then It is treated as 0
3. If any parameter is greater than str.lengtn(), that is to say it is out of bounds, it is treated as the same size as str.lengtn().
4. In the case of decimals: also starting from the first character, it is a string, "." is also a character, don't be scared.
end.

Guess you like

Origin blog.csdn.net/weixin_44998686/article/details/109009416