If you just want to remove "kB", you can try the following:
String line = inputStream.nextLine(); line = line.replaceFirst("kB", ""); double ss = Double.parseDouble(line);
If you want to remove everything that cannot be parsed using parseDouble , you need to use regexp:
String line = inputStream.nextLine(); line = line.replaceAll("[^-\\d.]", ""); double ss = Double.parseDouble(line);
This regular expression removes everything that is not:
- digit (you can use
0-9 instead of \\d if you are not interested in UTF-8 numbers) - or period (used for decimal)
- or minus sign (used for negative numbers).
source share