0

Hello all, I was wondering on how I would extract a number out of a String after a specified character. For example, if String s = "22+5+35" , how can I extract and store the numbers 22,5, and 35 in a ArrayList?

Edited by godzab

4
Contributors
3
Replies
24
Views
3 Years
Discussion Span
Last Post by Taywin
0

if you have to take into account other actions (+, -, :? *) and or brackets, split might not be the easiest way to go.

0

If you want to do a split (and the purpose is to obtain only digit characters), use regular expression that splits at any non-digit character (i.e. "[^\d]+"). Then you would get an array containing only digit characters.

If you are dealing with mathematic expressions, spliting a string into a char array would be OK because you will need to deal with the whole string (numbers & operands).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.