<bdo id='3lHif'></bdo><ul id='3lHif'></ul>
    1. <legend id='3lHif'><style id='3lHif'><dir id='3lHif'><q id='3lHif'></q></dir></style></legend>
      <i id='3lHif'><tr id='3lHif'><dt id='3lHif'><q id='3lHif'><span id='3lHif'><b id='3lHif'><form id='3lHif'><ins id='3lHif'></ins><ul id='3lHif'></ul><sub id='3lHif'></sub></form><legend id='3lHif'></legend><bdo id='3lHif'><pre id='3lHif'><center id='3lHif'></center></pre></bdo></b><th id='3lHif'></th></span></q></dt></tr></i><div id='3lHif'><tfoot id='3lHif'></tfoot><dl id='3lHif'><fieldset id='3lHif'></fieldset></dl></div>

    2. <tfoot id='3lHif'></tfoot>

        <small id='3lHif'></small><noframes id='3lHif'>

        在Java中从String中获取int,也包含字母

        时间:2023-10-01
            <tfoot id='gKJFK'></tfoot>
              <tbody id='gKJFK'></tbody>

                • <bdo id='gKJFK'></bdo><ul id='gKJFK'></ul>

                  <small id='gKJFK'></small><noframes id='gKJFK'>

                  <legend id='gKJFK'><style id='gKJFK'><dir id='gKJFK'><q id='gKJFK'></q></dir></style></legend>
                  <i id='gKJFK'><tr id='gKJFK'><dt id='gKJFK'><q id='gKJFK'><span id='gKJFK'><b id='gKJFK'><form id='gKJFK'><ins id='gKJFK'></ins><ul id='gKJFK'></ul><sub id='gKJFK'></sub></form><legend id='gKJFK'></legend><bdo id='gKJFK'><pre id='gKJFK'><center id='gKJFK'></center></pre></bdo></b><th id='gKJFK'></th></span></q></dt></tr></i><div id='gKJFK'><tfoot id='gKJFK'></tfoot><dl id='gKJFK'><fieldset id='gKJFK'></fieldset></dl></div>
                • 本文介绍了在Java中从String中获取int,也包含字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何从 423e 等字符串中获取 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() 失败,因为字符串必须完全是数字.

                  Integer.parseInt() fails since the string must be entirely a number.

                  推荐答案

                  除非你说的是 base 16 数字(有一种方法可以解析为 Hex),否则你需要明确地分离出你感兴趣的部分,然后转换它.毕竟,以 10 为底的 23e44e11d 之类的语义是什么?

                  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?

                  如果你确定你只有一个数字,正则表达式就可以解决问题.Java 有一个内置的正则表达式解析器.

                  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.

                  另一方面,如果您的目标是连接所有数字并转储 alpha,那么通过逐个字符迭代以使用 StringBuilder 构建一个字符串,然后解析该字符串,这是相当简单的.

                  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中从String中获取int,也包含字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在java中将double与int进行比较是否有效? 下一篇:为什么 == 对于某些 Integer 对象为真?

                  相关文章

                  最新文章

                • <legend id='oFUwP'><style id='oFUwP'><dir id='oFUwP'><q id='oFUwP'></q></dir></style></legend>
                  • <bdo id='oFUwP'></bdo><ul id='oFUwP'></ul>

                  1. <tfoot id='oFUwP'></tfoot>

                    1. <i id='oFUwP'><tr id='oFUwP'><dt id='oFUwP'><q id='oFUwP'><span id='oFUwP'><b id='oFUwP'><form id='oFUwP'><ins id='oFUwP'></ins><ul id='oFUwP'></ul><sub id='oFUwP'></sub></form><legend id='oFUwP'></legend><bdo id='oFUwP'><pre id='oFUwP'><center id='oFUwP'></center></pre></bdo></b><th id='oFUwP'></th></span></q></dt></tr></i><div id='oFUwP'><tfoot id='oFUwP'></tfoot><dl id='oFUwP'><fieldset id='oFUwP'></fieldset></dl></div>
                    2. <small id='oFUwP'></small><noframes id='oFUwP'>