Extract Integer Part in String

后端 未结 8 2120
灰色年华
灰色年华 2020-11-27 06:38

What is the best way to extract the integer part of a string like

Hello123

How do you get the 123 part. You can sort of hack it using Java\

8条回答
  •  迷失自我
    2020-11-27 06:40

    I believe you can do something like:

    Scanner in = new Scanner("Hello123").useDelimiter("[^0-9]+");
    int integer = in.nextInt();
    

    EDIT: Added useDelimiter suggestion by Carlos

提交回复
热议问题