Reputation: 964
I an trying to get the number after :
of the element string Min:30
to store it in int variable but I am getting a wrong result 5
as Output. How can I get the substring (the number) after :
in the element string?
if( element.startsWith("Min:") ) {
char[] Str = new char[2];
element.getChars(4, 6, Str, 0);
String string = str.toString();
System.out.println(string);
}
Upvotes: 0
Views: 108
Reputation: 2482
Use String.split();
element.split(":");
which returns an array splitted by the specified delimiter
String [] result = "Min:30".split(":"); //result[1]=30
int value = Integer.parseInt(result[1]);
Upvotes: 1
Reputation: 521259
int colonIndex = element.indexOf(":");
int value = Integer.parseInt(element.substring(colonIndex + 1, element.length()));
Upvotes: 3