Este artigo resume o método de implementação do Java para encontrar strings numéricos de strings. Compartilhe -o para sua referência, como segue:
int start = 0; string numstr = null; para (int j = 0; j <valorestr.Length () - 1; j ++) {if (caractere.isdigit (valuesstr.charat (j)) == False && start.isdigit (Valuess.Charat (j + 1)) == true) {start = j + 1; numstr = valuesstr.substring (start, valuesstr.length ()); }}Existem três maneiras de reimprimir de outros lugares:
1. Use as funções que vêm com Java
public static boolean isnumeric (string str) {for (int i = str.Length ();-i> = 0;) {if (! caractere.isdigit (str.charat (i))) {return false; }} retornar true;}2. Use expressões regulares
public static boolean isnumeric (string str) {padrão padrony = padrão.compile ("[0-9]*"); Return Pattern.Matcher (STR) .Matches ();}3. Use o código ASCII
public static boolean isnumeric (string str) {for (int i = str.Length ();-i> = 0;) {int chr = str.Charat (i); if (chr <48 || chr> 57) retorna false; } retornar true;}Espero que este artigo seja útil para a programação Java de todos.