package com.chap5.part1;
public class Example5_4 {
public static void main(String[] args) {
String path = "C:\\myfile\\2000\\result.txt";
//st.indexOf(String st1),返回st1字符串在st中的开始位置。
int index = path.lastIndexOf("\\");
//st.substring(int number),返回st中number位置后面的字符串。
String fileName = path.substring(index+1);
String newName = fileName.replaceAll(".txt", ".java");
System.out.println(index);
System.out.println(fileName);
System.out.println(newName);
String st = " we are student";
System.out.println(st);
//st.trim();去掉st前面的空格
st = st.trim();
System.out.println(st);
}
}
打开App,阅读手记