日期:2014-05-17  浏览次数:20683 次

新手提问 关于字符串判断的提问
小弟愚笨在此请教一个问题代码如下
 <tr>
     <td style="font-size:12px;">批量查询: </td>
     <td style="white-space:nowrap;">       
     <input id="bc_code1" class="mini-textarea"style="width:150px;height:100px;" />
     </td>
   </tr>

如果我在这里输入1234567890 1234567890 123456789
请问我该如何判断每段数字是否满10个字符
就是说
每10个字符判断一下错了话报错对的话后面隔一个空格在继续判断这样循环直到全部结束

------解决方案--------------------
String str = "1234567890 1234567890 0987654321 2345678901 234 562";
String[] ary = str.split(" ");
String flog = "";
for(int i= 0;i<ary.length;i++){
    if(ary[i].length()==10){
flog="正确";
}else{
flog="错误";
}
        System.out.println("第"+(i+1)+"个:"+flog);
}

------解决方案--------------------
可以用正则表达式进行 匹配吧!!
String s="1234567890 1234567890";
Pattern pattern = Pattern.compile("(//d{0,10})");
Matcher matcher = pattern.matcher(s);
if (matcher.find())
{
System.out.println(matcher.group());
}