Java string truncation method
This example describes how to intercept strings in Java. Share it with you for your reference. The specific implementation method is as follows:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13 |
Public static void main (String args []) {
// Start to intercept when this character appears for the first time
// String str = "abc. def ";
// String str = "abc. def. sdfsdf. fsdfd. ddddd. ggggg. ttttt ";
// String str1 = str. substring (str. indexOf (".") + 1, str. length ());
// Start to intercept the last occurrence of the character
String str = "http://wxj.videocc.net/wxj/images/2014/12/i3jwci4j.jpg ";
String str1 = str. substring (str. lastIndexOf ("/") + 1, str. length ());
// Truncates the last five characters
// String str = "http://wxj.videocc.net/wxj/images/2014/12/i3jwci4j.jpg ";
// String str1 = str. substring (str. length ()-5, str. length ());
System. out. println (str1 );
}
|
I hope this article will help you with java programming.