P
P
pthon2019-08-03 02:40:34
Java
pthon, 2019-08-03 02:40:34

How to find it in a string?

In general, it is necessary that Value1, value2, value3 be written to different variables. For example, a string is passed to jav'e Value1(Value2, Value3)and it is necessary for Java to understand that it is necessary to write the word before the brackets into a variable, there are 2 variables in brackets, separated by commas. I hope I explained everything clearly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-08-03
@pthon

String s = "Value1(Value2, Value3)";

Scanner scanner = new Scanner(s);
scanner.useDelimiter("\\(|,|\\)");

List<String> tokens = new ArrayList<>();
while (scanner.hasNext()) {
    tokens.add(scanner.next().trim());
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question