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

尚
Original
2019-12-31 10:46:5930222browse

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);

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

2. Through the method provided by StringUtils

StringUtils.substringBefore(“dskeabcee”, “e”);

/The result is: dsk/

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

StringUtils.substringBeforeLast(“dskeabcee”, “e”)

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!

Statement:
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