Krzysztof Pokrywka Krzysztof Pokrywka - 3 years ago 98
Java Question

Java String remove all characters after number

This is my string address : London, Jon 2 A
And I want to see in my output see London, Jon

I try do this :

String result = chapterNumber.substring(0, chapterNumber.indexOf("1"));


But I have to do 10 times from diffrent number maybe is better way to do this

Answer Source

try this

     String str = "London, Jon 2 A";
     System.out.println(str.replaceAll("\\d.*",""));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download