//字符串截取的用法:实现文件上传后,以当前的时间刻度做为文件名来保存
String imgFileName="d:/img/abc/dic0009.jpg";
//第一步:截取文件的后缀名
int index=imgFileName.lastIndexOf(".");
String fileExt=imgFileName.substring(index);
System.out.println("取到的文件后缀名:"+fileExt);
//第二步:获取当前的时间刻度
Date now=new Date();
String newFile= now.getTime()+fileExt;
System.out.println("保存新的文件名:"+newFile);
//替换,非法字符串的过滤的功能
String txt="26日的开罗解放广场俨然回到穆巴拉克即将被推翻的日子,埃及”";
txt=txt.replace("杀", "*");
System.out.println(txt);
//字符串分割的使用:用户输入一段英文字符后,将它转成骆驼命名的语句规范,如用户输入的是“this is a apple!”转换成 “ThisIsAAapple”
System.out.println("请输入一段英文语句:");
Scanner input=new Scanner(System.in);
String word=input.nextLine();
//第一步:使用split方法根据空格进行分割
String[] strs= word.split(" ");
String newStr="";
//第二步:遍历每个英语单词
for(String s:strs){
//把首字母改成大写,先截取每个单词的第一个字符
String top=s.substring(0, 1).toUpperCase();
//将首字母和原字符串中去除首字母后的字符进行拼接
newStr+=top+s.substring(1);
}
System.out.println(newStr);