The string object calls the contains method to determine whether the current string object contains the string s specified by the parameter, for example:
tom=student;
Then the value of tom.contains(stu) is true, and the value of tom.contains(ok) is false.
We need to know that the index position of the string starts from 0, for example:
Stringtom=dotcpp;
Then the characters corresponding to index positions 0, 1, 2, 3, 4, and 5 are the characters d, o, t, c, p, and p respectively.
The string calling method indexOf(String s) retrieves the string s from the beginning of the current string and returns the index position of the first occurrence of s. If the string s is not retrieved, the value returned by this method is -1.
The string calls the indexOf(String s, int startpoint) method to retrieve the string s starting from the startpoint position of the current string and returns the index position where s first appears. If the string s is not retrieved, the value returned by this method is -1.
The string calls the lastIndexOf(String s) method to retrieve the string s starting from the head of the current string and returns the index position where s last appeared. If the string s is not retrieved, the value returned by this method is -1.
For example:
Stringtom=Iamagoodcat;tom.indexOf(a);//The value is 2tom.indexOf(good,2);//The value is 7tom.indexOf(a,7);//The value is 13tom.indexOf(w,2); //The value is -1
The string object calls this method to obtain a substring of the current string, which is the string intercepted from the startpoint of the current string to the end.
The string object calls the substring(int start, int end) method to obtain a substring of the current string. The substring is a string obtained by copying the characters from the start index position of the current string to the end-1 index position.
For example:
Stringtom=I like basketball;Strings=tom.substring(1,3);
Then, s is "like".
Note : s is not "like basket".
A string s obtains a string object by calling the trim() method. The string object is the string of s with leading and trailing spaces removed.
Note : If you want to intercept the file name in the file path, you need to use the escape operation "\" to represent "" in the string.