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

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

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

        Get int from String, also containing letters, in Java(在Java中从String中获取int,也包含字母)
      2. <i id='41Naa'><tr id='41Naa'><dt id='41Naa'><q id='41Naa'><span id='41Naa'><b id='41Naa'><form id='41Naa'><ins id='41Naa'></ins><ul id='41Naa'></ul><sub id='41Naa'></sub></form><legend id='41Naa'></legend><bdo id='41Naa'><pre id='41Naa'><center id='41Naa'></center></pre></bdo></b><th id='41Naa'></th></span></q></dt></tr></i><div id='41Naa'><tfoot id='41Naa'></tfoot><dl id='41Naa'><fieldset id='41Naa'></fieldset></dl></div>
          <bdo id='41Naa'></bdo><ul id='41Naa'></ul>

              <small id='41Naa'></small><noframes id='41Naa'>

              <tfoot id='41Naa'></tfoot>
                <legend id='41Naa'><style id='41Naa'><dir id='41Naa'><q id='41Naa'></q></dir></style></legend>
                  <tbody id='41Naa'></tbody>

                  本文介绍了在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,也包含字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

                      <tfoot id='kQ9Xd'></tfoot>
                      <i id='kQ9Xd'><tr id='kQ9Xd'><dt id='kQ9Xd'><q id='kQ9Xd'><span id='kQ9Xd'><b id='kQ9Xd'><form id='kQ9Xd'><ins id='kQ9Xd'></ins><ul id='kQ9Xd'></ul><sub id='kQ9Xd'></sub></form><legend id='kQ9Xd'></legend><bdo id='kQ9Xd'><pre id='kQ9Xd'><center id='kQ9Xd'></center></pre></bdo></b><th id='kQ9Xd'></th></span></q></dt></tr></i><div id='kQ9Xd'><tfoot id='kQ9Xd'></tfoot><dl id='kQ9Xd'><fieldset id='kQ9Xd'></fieldset></dl></div>

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

                        <tbody id='kQ9Xd'></tbody>
                      • <legend id='kQ9Xd'><style id='kQ9Xd'><dir id='kQ9Xd'><q id='kQ9Xd'></q></dir></style></legend>

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