2013年11月4日星期一

About the judge sentences the issue

String SYHC = rs1.getString ("syhs");
if (SYHC == "0" | | SYHC == "1" | | SYHC == "2" | | ; SYHC == "3" | | SYHC == "4" | | SYHC == "5" | | SYHC == " ; 6 "| | SYHC ==" 7 "| | SYHC ==" 8 "| | SYHC ==" 9 ") {
.........
.........
}


As written above . I want to determine whether SYHC number between 0 and 9 .

Is there an easier way ?

seeking advice.

------ Solution ------------------------------------ --------
If syhs field holds the string:
if (SYHC.length == 1 && SYHC.compareTo ("0")> = 0 && SYHC.compareTo ("9") <= 0)

If syhs field holds the numbers:
double SYHC = rs1.getDouble ("syhs");
if (SYHC> = 0 && SYHC <= 0)
------ For reference only -------------------- -------------------
regular judgment .
------ For reference only -------------------------------------- -
String s = "^[0-9]$";
Pattern pattern = Pattern.compile(s);
Matcher m = pattern.matcher("syhs");
                boolean b = m.find();//判断是否匹配

------ For reference only ------------------------------- --------
String SYHC = "0";
String num = "1234567890";
if (num.contains (SYHC)) {
System.out.println ("SYHC is num ~!");
}
------ For reference only --------------------------------- ------
convert between 0,9 shaping determine whether you can also use regular and so on. . .
------ For reference only -------------------------------------- -
String SYHC = "8";//0-9
String s = "^[0-9]$";
Pattern pattern = Pattern.compile(s);
Matcher matcher = pattern.matcher(SYHC);

while (matcher.find()) {
System.out.println(matcher.group());
System.out.println("包含");
}

------ For reference only ------------------------------- --------
regex
.
------ For reference only -------------------------------------- -



Thank you .

没有评论:

发表评论