« Return to Thread: Does Such A Tag Already Exist?

Re: Does Such A Tag Already Exist?

by bilcorry :: Rate this Message:

Reply to Author | View in Thread

Jason Huck wrote on 6/30/2009 12:58 PM:
> This would work with any order, but would need to be space-delimited:

Building on yours, this makes the whitespace unimportant, the order is unimportant, extraneous text is unimportant, and only uses the first found instance of each time component:

=========================================================
[

define_tag('string_toduration', -req='in');
        local('d' = 0, 'h' = 0, 'm' = 0, 's' = 0);
        protect; #d = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*d')->get(2)); /protect;
        protect; #h = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*h')->get(2)); /protect;
        protect; #m = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*m')->get(2)); /protect;
        protect; #s = integer(string_findregexp(#in,-find='(?i)(\\d+)\\s*s')->get(2)); /protect;
        return(duration( -day=#d, -hour=#h, -minute=#m, -second=#s));
/define_tag;

string_toduration('1d 17h 45m 22s');'<br>';
string_toduration('Duration is 17h 1 d45 m22s');'<br>';
string_toduration('Duration is 1 Day 17 Hours 45 Minutes and 22 Seconds');'<br>';
string_toduration('17h 1 d45 m22s 0d0h0m0s');'<br>';
]

LP8:  41:45:22
      41:45:22
      41:45:22
      41:45:22
=========================================================


- Bil


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


 « Return to Thread: Does Such A Tag Already Exist?