Split time string to value
Hans Karlsen (talk | contribs) (Created page with "I was asked on how to split a string from a textbox to its given hour and minute values. let x='22:12'.split(':'.tochararray) in ( Integer.Parse(x.at0(0)).asstring+' hour...") |
(Automatically adding template at the end of the page.) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
I was asked | I was asked how to split a string from a textbox to its given hour and minute values. | ||
let x='22:12'.split(':'.tochararray) in | let x='22:12'.split(':'.tochararray) in | ||
( | ( | ||
Integer.Parse(x.at0(0)).asstring+' hours and '+Integer.Parse(x.at0(1)).asstring+' minutes' | Integer.Parse(x.at0(0)).asstring+' hours and '+Integer.Parse(x.at0(1)).asstring+' minutes' | ||
) | ) | ||
Why you | Why, you ask? Well, consider having this in a ReverseDerived string representing the clock. Once you have the parts, you can update a Datetime value with these for storage. | ||
Or maybe like this: | Or maybe do something like this: | ||
let x='22:12'.split(':'.tochararray) in( | let x='22:12'.split(':'.tochararray) in( | ||
DateTime.Parse('0001-01-01 '+x.at0(0)+':'+x.at0(1)) | DateTime.Parse('0001-01-01 '+x.at0(0)+':'+x.at0(1)) | ||
) | ) | ||
Later, I found that this article addresses the same issue in a wider context together with the derived settable attribute here: [[Derived settable attributes]]. | |||
[[Category:OCL]] | |||
{{Edited|July|12|2024}} |
Latest revision as of 15:47, 10 February 2024
I was asked how to split a string from a textbox to its given hour and minute values.
let x='22:12'.split(':'.tochararray) in ( Integer.Parse(x.at0(0)).asstring+' hours and '+Integer.Parse(x.at0(1)).asstring+' minutes' )
Why, you ask? Well, consider having this in a ReverseDerived string representing the clock. Once you have the parts, you can update a Datetime value with these for storage.
Or maybe do something like this:
let x='22:12'.split(':'.tochararray) in( DateTime.Parse('0001-01-01 '+x.at0(0)+':'+x.at0(1)) )
Later, I found that this article addresses the same issue in a wider context together with the derived settable attribute here: Derived settable attributes.
This page was edited more than 11 months ago on 02/10/2024. What links here