Quote:
Originally Posted by DavidC
Whatever's most appropriate, I'm therefore guessing vba
Scan the string from left to right (say, using a for loop, like for i = 1 to len(s), then using mid(s,i,1) to examine the current character), while storing numeric characters in a temporary string buffer. Whenever you encounter a non-numeric character, y/w/d/h/m/s, you take whatever is in the buffer, and convert it to a number (CInt/CDbl), then to seconds, add it to a running total, and empty the buffer.
Depending on your error-checking needs, you may want to detect whether a given unit's been used twice, whether the units are in the right order, whether the input string ends with a unit as opposed to a number, etc.