文章詳情頁
正則表達(dá)式 - java獲得一個(gè)String字符串中第一個(gè)數(shù)字的下標(biāo),并截取后面的6位和前面的地區(qū)
瀏覽:92日期:2024-02-16 09:35:48
問題描述
問題解答
回答1:String s = '杭州20170222ax';Pattern p = Pattern.compile('([0-9].{5,5})');Matcher m = p.matcher(s);m.find();System.out.println(m.group(1));回答2:
遍歷字符串,str.charAt(i)>=48 && str.charAt(i)<=57判斷數(shù)字,第一個(gè)符合要求的,就是下標(biāo)
回答3:System.out.println( new Scanner('寧波20170222呵呵22').useDelimiter('D+').nextInt());回答4:
String s = '杭州20170222ax';char[] chars = s.toCharArray();for (int i = 0; i < chars.length; i++) { if (Character.isDigit(chars[i])) {System.out.println(s.substring(i, i + 6));break; }}回答5:
http://www.cnblogs.com/androi...
標(biāo)簽:
java
排行榜

熱門標(biāo)簽