最普通的一个写法
public static void countChar(String strFile, char ch)throws Exception {
System.out.println("");
FileInputStream in = new FileInputStream(strFile);
byte arrRead[]=new byte[1024];
int readBytes;
int count = 0;
while( (readBytes=in.read(arrRead) ) >0 ){
for(int i=0;i
count++;
}
}
}
in.close();
System.out.println( String.format("In \"%s\"count of '%c' is %d", strFile, ch, count) );
}
使用javascript结合正则表达式来判断
var str = "你的文章字符串";
var patt = new RegExp("a","g");
var result;
var num;
while ((result = patt.exec(str)) != null) {
num++;
}
alert(num);//输出a在字符串中出现的次数