首页 > 其他 > 详细

字符集及判断字符所在字符串位置

时间:2015-12-18 16:19:34      阅读:170      评论:0      收藏:0      [点我收藏+]
//查找字符或字符串
		int in = str2.indexOf("d");
		
		System.out.println("ab =" + in);
		
		int la = str2.lastIndexOf("d");//课后
		
		System.out.println("d =" + la);
		
		String newStr = str2.substring(5);
		
		newStr = str2.substring(5,6);
		
		System.out.println("substring() =" + newStr);
		
		str2 = " ab cdd s ";
		
		//去除前后空格
		System.out.println("去空格 =" + str2.trim() + "后面");
		
		//查找替换
		System.out.println("查找替换空格 =" + str2.replace(" ", "") + "后面");
		
		str2 = "abc,你好,abcd";
		
		System.out.println("查找替换 =" + str2.replace("abc", "李四") + "");
		
		System.out.println("查找替换 =" + str2.replaceFirst("abc", "张三") + "");
		
		str2 = "abcdef";
		
		//判断字符串开始和结束
		System.out.println("判断起始1 =" + str2.startsWith("abc"));
		
		System.out.println("判断起始2 =" + (str2.indexOf("abc") == 0));
		
		System.out.println("判断结束  =" + str2.endsWith("ef") + "\t");
		

  

字符集及判断字符所在字符串位置

原文:http://www.cnblogs.com/fangchongyan/p/5057173.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!