Home > Java > JavaBase > How to get the first few digits of a string in java

How to get the first few digits of a string in java

Release: 2019-12-31 10:46:59
Original
30204 people have browsed it

How to get the first few digits of a string in java

Java method of intercepting the first digits of a string:

Recommendation: java video tutorial

1. Through subString( ) method to perform string interception.

subString provides different interception methods through different parameters

Pass in 2 index values

String sb = "bbbdsajjds";
sb.substring(0, 4);
Copy after login

Start from index number 0 and end at index 4 (and do not include Index 4 interception is included, which means that the actual interception is characters 0 to 3);

The running results are as follows:

bbbd
Copy after login

2. Through the method provided by StringUtils

StringUtils.substringBefore(“dskeabcee”, “e”);
Copy after login

/The result is: dsk/

Here, the first "e" is used as the standard.

StringUtils.substringBeforeLast(“dskeabcee”, “e”)
Copy after login

The result is: dskeabce

The last "e" shall prevail here.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of How to get the first few digits of a string in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template