-2
A
回答
0
如果它總是在格式number words
,那麼您可以:
int number = Integer.parseInt(lineString.replace(/\D+/, '')); // This uses a regex to remove all letters
OR
int number = lineString.split(" ")[0]; // Splits string by spaces and gets the first token, which will be numbers
其中lineString
是要分析,像1 something
的字符串。
0
int result = Integer.parseInt(mString.substring(0,1));
0
沒有正則表達式的一個簡單的方法:
private int readNum(String input){
String buffer = "";
char[] chars = input.toCharArray();
for(char c: chars){
if(Character.isDigit(c))
buffer = buffer + c;
else
break;
}
return Integer.parseInt(buffer);
}
0
您可以使用NumberFormat類 try { Log.i("TAG",((Number)NumberFormat.getInstance().parse("123efdsf4")).intValue()+""); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
的方法「解析」,直到找到一個字符,此方法將解析字符串。
相關問題
- 1. 讀取不以[]開頭的行] dos
- 2. 如何只從文件讀取一行(它的頭)?
- 3. 打開的文件只讀取一行
- 4. 如何讀取以python中的算術字符開頭的行3
- 5. 如何讀取以零開頭的整數?
- 6. 如何從頭再次開始從文本中讀取行?
- 7. 讀取字的函數只讀取每隔一個字母
- 8. 如何在shell中逐行讀取可變行時驗證行以數字開頭
- 9. nhibernate只讀頭數據
- 10. 如何獲取以A開頭的行(大寫字母)?
- 11. 如何使textField的第一個字符只以字母開頭?
- 12. 如何在使用fgets()讀取一行後移回到前一行的開頭?
- 13. 如何選擇以Rails中的數字開頭的行?
- 14. 如何選擇以PostgreSQL中的數字開頭的行?
- 15. 刪除行開頭的數字
- 16. C#如何只讀取字節數組[]中的選定值?
- 17. 如何只讀取matlab文本文件中的數字列?
- 18. 如何只讀取文件中的數據(忽略字符串)?
- 19. 讀取以DOT開頭的文件名「」。「
- 20. 如何將ifstream返回到剛剛用C++讀取的行的開頭?
- 21. 如何在整數或字符串的開頭讀取0?然後將它們進行比較
- 22. 文件讀取器只讀取文件的偶數行
- 23. 如何grep以數字或空格開頭的行
- 24. 如何在每行的開頭添加數字?
- 25. 如何刪除文件行開頭的數字
- 26. 如何使StreamReader從文本文件的開頭讀取
- 27. 獲取以一些數字開頭的行
- 28. 碼頭只讀套接字量
- 29. 如何讀取Python中的字符數,行數和單詞數
- 30. 正則表達式,從字符串的開頭讀取