we have a list of strings, the user must enter the minimum and maximum numbers, after which the program checks whether the string contains a number in the range from minimum to maximum
|
1 answer
Regular expressions will most likely help you in your question. Regular expressions (eng. Regular expressions) is a formal language for searching and manipulating with interlaces in the text, based on the use of metacharacters (jokers, English wildcard characters). In essence, this is a sample string (English pattern, in Russian it is often called a “pattern”, “mask”), consisting of characters and metacharacters and specifying a search rule.
import java.util.regex.*; String msg = "Строка с цифрами 12345"; Pattern pattern = Pattern.compile("[0-9]+"); Matcher matcher = pattern.matcher(msg); while(matcher.find()){ Integer result = new Integer(msg.substring(matcher.start(),matcher.end())); if(result > 100) System.out.println( result + " > 100" ); } |
Тут 123 что-то 888 с 65 числами. How doescontainshelp determine whether there are numbers in strings in the range of16 to 311? - Qwertiy ♦