public class TestReplaceString { public static void main(String[] args) { String a = new String("aaa<br>bbb<br>ccc"); System.out.println(a); String b = a.replace("<br>", "\n"); //String b = a.replaceAll("<br>", "\n"); System.out.println(b); } }
public class test {
/** * @param args */ public static void main(String[] args) { String s = "http://localhost:8080/Blog/article.do?messageId=16"; System.out.println(new test().getLastPageNameRemovePath(s)); }
public String getLastPageNameRemovePath(String ss) { int pos = ss.lastIndexOf("/"); ss = ss.substring(pos); return ss; } }
public class TestStringOperator {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String s = new String("abcd.jpg"); String suffix = new TestStringOperator().getFileSuffix(s); System.out.println("后缀名 = "+suffix);
String s2 = new String("jakarta-tomcat-5.5.7\\webapps\\BlogJavaBean\\index.jsp"); s2 = new TestStringOperator().getSubStrRealPath(s2); System.out.println("realpath = "+s2);
String s3 = new String("D:\\jakarta-tomcat-5.5.7\\webapps\\BlogJavaBean\\images\\header\\施文俊"); s3 = new TestStringOperator().getUserHeadImg(s3); System.out.println("s3.indexOf[images\\header] = "+s3);
String s4 = new String("D:\\jakarta-tomcat-5.5.7\\webapps\\BlogJavaBean\\images\\header\\施文俊"); s4 = new TestStringOperator().getUserHeadImg(s4); s4 = s4.replace('\\', '/'); System.out.println("s4.replace[images\\header] = "+s4);
String s5 = new String("/BlogJavaBean/no_name_one.jsp?messageId=6"); s5 = new TestStringOperator().getLastPageNameRemovePath(s5); System.out.println("s5 = s5.substring(pos) = "+s5); }
public String getLastPageNameRemovePath(String ss) { int pos = ss.lastIndexOf("/"); ss = ss.substring(pos); return ss; }
public String getUserHeadImg(String ss) { int pos = ss.indexOf("images\\header"); ss = ss.substring(pos); return ss; }
public String getFileSuffix(String fileName) { int pos = fileName.indexOf("."); fileName = fileName.substring(pos); return fileName; }
public String getSubStrRealPath(String scRealPath) { int pos = scRealPath.lastIndexOf("\\"); scRealPath = scRealPath.substring(0, pos+1); return scRealPath; }