Can anyone suggest the best approach for metric conversion of string values? for instance distance values,and temperatures
For instance say I have a string containing some unknown inches value
And the inches sign can either be the proper double prime OR double quotes.
So, I'm guessing as a first step I would search for double prime or double quotes preceded by a number value, then parse out and convert this number value. But this doesn't seem foolproof for instances when it is actually a doublequote, NOT an in开发者_JAVA技巧ches sign
You can split your input string like this:
split('"')
or this:
split("''")
Then pass the results of the returned array to parseInt()
or parseFloat()
.
精彩评论