I have a string that containg alaphabets for example :
a) 254.69 meter b) 26.56 cm c) 23.36 inches d) 100.85 ft
I want to remove all the alphabets (units) from the above mentiones strings so that I can call double.Parse method !!
Please help!!
I have a string that containg alaphabets for example :
a) 254.69 meter b) 26.56 cm c) 23.36 inches d) 100.85 ft
I want to remove all the alphabets (units) from the above mentiones strings so that I can call double.Parse method !!
Please help!!
You should be able to solve this using Regex. Add the following reference to your project:
using System.Text.RegularExpressions;
after that you can use the following:
string value = Regex.Replace(, "[A-Za-z ]", ""); double parsedValue = double.Parse(value);
Assuming you have only alphabetic characters and space as units.
Use CharMatcher API from Google's Guava library:
String magnitudeWithUnit = "254.69 meter";
String magnitude = CharMatcher.inRange('a', 'z').or(inRange('A', 'Z')).removeFrom(magnitudeWithUnit);
Do static-import CharMatcher.inRange(..). You can trim the results for trailing space.