java int字母,从Java中获取int,也包含字母
How can I get the int value from a string such as 423e - i.e. a string that contains a number but also maybe a letter?
Integer.parseInt() fails since the string must be entirely a number.
解決方案
Unless you're talking about base 16 numbers (for which there's a method to parse as Hex), you need to explicitly separate out the part that you are interested in, and then convert it. After all, what would be the semantics of something like 23e44e11d in base 10?
Regular expressions could do the trick if you know for sure that you only have one number. Java has a built in regular expression parser.
If, on the other hands, your goal is to concatenate all the digits and dump the alphas, then that is fairly straightforward to do by iterating character by character to build a string with StringBuilder, and then parsing that one.
總結
以上是生活随笔為你收集整理的java int字母,从Java中获取int,也包含字母的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【word论文排版教程4】样式的应用
- 下一篇: java栈顶元素_栈在Java类库中的实