Captai-N
Captai-N

Reputation: 1502

Substring a string until first number character in Java

how can i extract a string until he's first number character? For example i have this string and i want to cut them from the start until the first nummeric ( 1 or 12). The text is dynamic so only the start word is every time the same not the number and not the position of the number.

geschäftsführerin anna maier tannenstraße 12 landau

Upvotes: 1

Views: 5435

Answers (1)

Bogdan Oros
Bogdan Oros

Reputation: 1299

You can use the

public String[] split(String regex)

method in String class, just need to pass a regex pattern with numbers like [0-9].

String getSubstringUntilFirstNumber(String source) {
    return source.split("[0-9]")[0];
}

Upvotes: 5

Related Questions