I have a string in which size of a particular media is given. I want to search size and print it.
sampleString = "Sample text having sample 4.5GB"
Note: string can have number of patterns such that [4.0GB, 4.0MB, 4GB, 70MB]
"GB" or "MB" could be integer or float.
My idea is to search the pattern like above mentioned in a string and then split it with MB or GB whichever is found and then grab the integer or float corresponding to that.
I have started finding patterns but code couldn't work. Below is my code:
public class CheckSize {
public static void main(String args[]) {
System.out.println(size("Sample text having sample 4.5GB"));
}
private static String size(String mString) {
Float size = 0f;
String mbSize = "";
String gbSize = "";
boolean found = mString.matches("\\d");
if (found) {
return "size available";
}
else {
return "size is not available";
}
}
}
Please help.