import java.util.regex.Pattern; import java.util.regex.Matcher;public class DiffTesting{ public static void main(String args[]){ String a="2998808ORDERS_I I832892,004,000,C13S015345,C13S015345,RO,090017,ESPRBJUN'04,00003500,00000000.00,20, ,20040614,00003500,00000000, ,Y,20040614,000200,0000,RO,R3,D2,MIMOSA-W AS RIBBON CARTRIDGE"; String a1="a,b,c,d,e,f,g,h,i,j,"; if(a.indexOf(",") != -1){ System.out.println("this is orders type"+a.indexOf(",")); }//the end of if if(a1.indexOf(",") != -1){ System.out.println("this is orders type"+ a1.indexOf(",")); }//the end of if Pattern pattern = Pattern.compile(","); Matcher matcher = pattern.matcher(a); int count = 0; while (matcher.find()) { count++; } System.out.println("count = " + count); }//the end of the static void}//the end of class这样可以找到他的个数
import java.util.regex.Matcher;public class DiffTesting{
public static void main(String args[]){
String a="2998808ORDERS_I I832892,004,000,C13S015345,C13S015345,RO,090017,ESPRBJUN'04,00003500,00000000.00,20, ,20040614,00003500,00000000, ,Y,20040614,000200,0000,RO,R3,D2,MIMOSA-W AS RIBBON CARTRIDGE";
String a1="a,b,c,d,e,f,g,h,i,j,";
if(a.indexOf(",") != -1){ System.out.println("this is orders type"+a.indexOf(",")); }//the end of if
if(a1.indexOf(",") != -1){ System.out.println("this is orders type"+ a1.indexOf(",")); }//the end of if
Pattern pattern = Pattern.compile(",");
Matcher matcher = pattern.matcher(a);
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println("count = " + count);
}//the end of the static void}//the end of class这样可以找到他的个数
012345.................24
"a,b,c,d,e,f,g,h,i,j,"
01index 其实就是数组下标的意思
如果你把 String 看成一个字符数组(char[])的话
这个数字就是那个字符数组某元素的下标indexOf(String str) 返回的是 str 在原字符串中"第一次出现"的位置的下标
没有计算总数的功能详见 SDK 文档
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#indexOf(java.lang.String)