Reputation: 3048
I got a String "1/3" where I want to get only the number 1
Is it possible to get it without using "1/3".split("\\/") ?
Upvotes: 1
Views: 938
Reputation: 240948
you can use indexOf()
and subString()
to get 1
String str = "1/3";
System.out.println(str.substring(0, str.indexOf("/")));
Must See
Upvotes: 4
Reputation: 12720
Or with some regex as well:
String s = "1/3";
String m = s.replaceAll("(\\d+)/.+", "$1");
Upvotes: 0