字符串的截取,分割,替换

		//字符串截取的用法:实现文件上传后,以当前的时间刻度做为文件名来保存
		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);
		

 

转载于:https://www.cnblogs.com/zhuangjixiang/archive/2012/11/27/2791344.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值