package test1;
/*** * @author Administrator*1:查找一个字符串当中指定字符所出现的次数*/
public class 字符查找 {public static void main(String[] args) {// TODO Auto-generated method stubString 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);}}
详细解决方案
去除字符串当中指定重复字符
热度:12 发布时间:2023-10-24 03:50:29.0
相关解决方案