Java字符串分离数字序列

huangapple go评论75阅读模式
英文:

Java string separate number sequence

问题

我得到一个始终具有相同长度的字符串生成的数字,例如:

0107612733631449211907028445

现在我想要获得最后10位数字的两个单独字符串:

010761273363144921**1907028445**

以及另一个包含这些数字的字符串:

0107612733**63144**9211907028445

这些所需数字的位置始终相同,开头的数字对我来说不重要,可以省略。

我该如何获得这两个字符串?

英文:

I get a number generated as a string that always has the same length, for example:

0107612733631449211907028445

Now I wan't to get two separate strings with the last 10 digits:

010761273363144921**1907028445**

And another string with these digits

0107612733**63144**9211907028445

The positions of these needed numbers are always the same, the numbers at the beginning are not important for me and can be omitted.

How can I get these two strings?

答案1

得分: 1

[Java文档 .substring 方法][1]

    String number = "0107612733631449211907028445";
    String last10 = number.substring(number.length()-10);
对于中间的数字,使用 `substring(int beginIndex, int endIndex)` 方法。
  [1]: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int)
英文:

[Java docs .substring method][1]

String number = "0107612733631449211907028445";
String last10 = number.substring(number.length()-10);

for middle numbers use substring(int beginIndex, int endIndex)
[1]: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring(int)

huangapple
  • 本文由 发表于 2020年4月6日 22:35:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/61062241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定