天天看点

字符串进行截取替换操作实例代码

public class jieQuTiHuan {
	public static void main(String args[]) {
		//原字符串,自己定义
		String str = "D:\\Program Files\\apache-tomcat-6.0.29\\webapps\\Car_Lease\\file\\car_1.jpg";
		//输出原字符串
		System.out.println("原字符串:" + str);
		//替换字符串
		String replaceStr = str.replace("\\", "/");
		//输出替换后的字符串
		System.out.println("被替换后:" + replaceStr);
		//截取字符串
		String charstr = "Car_Lease/";
		//输出截取后的字符串
		System.out.println("被截取后:"	+ replaceStr.substring(replaceStr.indexOf(charstr) + charstr.length(),replaceStr.length()));
	}
}