package test1; /** * * @author Administrator *1:查找一个字符串当中指定字符所出现的次数 */ public class 字符查找 { public static void main(String[] args) { // TODO Auto-generated method stub String s1="abaacddfdsfdflkm"; int count=0; int fromIndex=0; int num; // System.out.println(s1.indexOf('f',11)); while(fromIndex<s1.length()) { fromIndex=s1.indexOf('f',fromIndex); if(fromIndex==-1) break; fromIndex++; count++; } System.out.println(count); /* * 进行字符的截取,获取到字符串对象当中的第一个字符对象,然后将该字符对象保存到一个StringBuffer对象当中,之后将字符串对象当中的和第一个字符相同的 * 所有字符都用""空字符来进行替换 * */ String srcStr=""; StringBuffer stringBuffer=new StringBuffer(); char c1; while(true) { if(s1.length()==0) { break; } c1=s1.charAt(0); stringBuffer.append(c1); s1=s1.replace(String.valueOf(c1),""); } System.out.println(stringBuffer); } }
去除字符串当中指定重复字符
猜你喜欢
转载自blog.csdn.net/qq_34970891/article/details/80612874
今日推荐
周排行