I am trying to use jQuery to break right ascension and declination data into their constituents (hours, minutes, and seconds) and (degrees, arc-minutes, and arc-seconds), respectively from a string and store them in variables as numbers. For example:
$dec = "-35:48:00" -> $dec_d = -35, $dec_m = 48, $dec_s = 00
Actually, the data resides in a cell (with a particular class (‘ra’)) in a table.
At present, I have gotten this far:
var $dec = $(this).find(".ra").html();
This gives me the declination as a string but I cannot figure out how to parse that string.
I figured out the regular expression (-|)+\d+ (this gives me -35 from -35:48:00) to get the first part. How do I use that in conjunction with my code above?
This should do it:
parts[0]would then be-35,parts[1]would be48, andparts[2]would be00You could run them all through
parseInt(parts[x], 0)if you want integers out of the strings:I should point out this really has nothing to do with jQuery and is a Javascript problem (past getting the values out of the HTML document, at least) – The practice of prefixing a variable with a
$is usually done to signify that the variable contains a jQuery collection. Since in this situation it contains HTML, it is a little misleading