Jeff wrote: ↑February 4th, 2021, 1:29 pm
Code: Select all
[ObviousWebParserMeasure]
Measure=String
String=00:30:00
[Hours]
Measure=String
String=[ObviousWebParserMeasure]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(\d+)\:(\d+)\:(\d+)":"\1"
[Minutes]
Measure=String
String=[ObviousWebParserMeasure]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(\d+)\:(\d+)\:(\d+)":"\2"
[Seconds]
Measure=String
String=[ObviousWebParserMeasure]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(\d+)\:(\d+)\:(\d+)":"\3"
[TimerToSeconds]
Measure=Calc
Formula=Seconds + Minutes * 60 + Hours * 3600
I've seen strings getting converted to numbers (without decimal place) before using Rainmeter, but this time it dosen't work, is there something with my RegExp?
When you use the number value of measures, like you are in your Calc measure, it will literally use the number value, and will ignore any changes to the string value you make with RegExpSubstitute. You are going to need to use the string value AS a number, like this:
Code: Select all
[TimerToSeconds]
Measure=Calc
DynamicVariables=1
Formula=[Seconds] + [Minutes] * 60 + [Hours] * 3600
When you use a [SectionVariable] in a formula, that will by default use the string value, converting it to a number if it can. This will first apply the RegExpSubstitute and use the altered string, which is what you want.
Notes:
A String measure will have a number value if the string is numeric, however, that number value will be based on the original string value of the measure, and no RegExpSubstitute will be used in that context. Substitute is applied when and where the string value is "used", and doesn't in any way actually change the value of the measure itself.
The number value of all your String measures, which are all based on the string "00:30:00", will always be zero. The measure will attempt to convert the string to a valid number, but that will end up with a number value of 00, since that is the point where the string stops being numeric. The ":" in the string is not a valid numeric value, so it gets the "00", stops trying when it gets to ":", and you end up with 00, or zero...
There is no need to use the
:EscapeRegExp modifier on the [SectionVariable] in this instance. That modifier might be used if you are using the string value of one measure as a component of a regular expression on another measure.