09-19-2011 08:11 AM
i have a string month which is one character long (1234567890AB) that I want to convert into a decimal month (123456789,10,11,12)
Solved! Go to Solution.
09-19-2011 08:15 AM - edited 09-19-2011 08:16 AM
Did you look in the String palette at the conversion functions?
Is your 0 -> 10 a typo, or is it actually supposed to be that?
09-19-2011 08:18 AM - edited 09-19-2011 08:19 AM
There are two functions called Decimal String to Number and Hexadecimal String to Number (on Function -> String -> String/Number Conversion)
09-19-2011 08:40 AM
1=Jan=1, 2=Feb=2, 3=...9=Sep=9, 0=Oct=10, A=Nov=11, B=Dec=12.
I can do it using "matching regular expression" vi but I'm wondering if there's an easier way. The decimal and hex conversion will screw up at the 0 =10.
Thanks
09-19-2011 08:52 AM - edited 09-19-2011 08:52 AM
I see two easy ways to do this. After doing the hex to number conversion, you can do a case statement for the value. For the default case, just pass though the value. For case 0, pass out 10, for case 10, 11 (A, B) increment the value before passing it out.
The other option is have the data type for the hex conversion be an I32 and index an array. The array will just be out of order [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12].
09-19-2011 08:52 AM - edited 09-19-2011 08:54 AM
Well, there's always the simple lookup method:
Should there another papal decree to change the calendar, then you'd have some problems. Until then, though, you're probably safe...
09-19-2011 08:53 AM
You might want to make a 1-D array of those characters, and do a search 1-D array. If you set up the 1-D array correctly, the returned index will be your month number.
09-19-2011 08:55 AM
@ahhah wrote:
1=Jan=1, 2=Feb=2, 3=...9=Sep=9, 0=Oct=10, A=Nov=11, B=Dec=12.
I can do it using "matching regular expression" vi but I'm wondering if there's an easier way. The decimal and hex conversion will screw up at the 0 =10.
Thanks
Time to break out a custom Strict Type Ring
09-19-2011 09:22 AM
Thanks. All great suggestions!