字符串的截取拼接

public class CH02_3 {
public static void main(String[] args) {
String str = "qwertweyu";
int index = str.indexOf('w');
System.out.println(index);

int index2 = str.indexOf("we");
System.out.println(index2);

int index3 = str.lastIndexOf('w');
System.out.println(index3);

int index4 = str.lastIndexOf("we");
System.out.println(index4);

String substr=str.substring(4);
System.out.println(substr);

String str2 = "I LOVE CODE";
String substr2 = str2.substring(2,6);
System.out.println(substr2);
//去掉两边空格
String str3 = " I LOVE CODE ";
String substr3 = str3.trim();
System.out.println(substr3);
//判断java 文件
String a = "abc.java";
int b = a.lastIndexOf(".java");
System.out.println(b);
System.out.println(a.endsWith(".java"));
System.out.println(a.startsWith("ab"));

int index6 = a.lastIndexOf(".");
String substr6 = a.substring(index6);
if(substr6.equals(".java")){
System.out.println("是java文件");
}else{
System.out.println("不是java文件");
}
System.out.println("****原歌词格式*****");
String poem = "长亭外 古道边 芳草碧连天 晚风扶 柳笛声残 夕阳山外山";
System.out.println(poem);
System.out.println("****修改后的歌词*****");
String m [] =poem.split(" ");
for(int i=0;i<m.length;i++){
System.out.println(m[i]);
}


}
}

posted @ 2016-11-03 13:49  造西  阅读(1098)  评论(0编辑  收藏  举报