It is currently April 16th, 2024, 3:03 pm

cut and convert string index to number

Get help with creating, editing & fixing problems with skins
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

cut and convert string index to number

Post by nikko »

hello. i have question how to use values where is -09:30 in this string 2021-03-31T03:47:23.768-09:30 ? it can be + or - before that numbers and i would like to cut it and convert to integer. i would like it to be in format -9.30 in this case and if not 0 first then of corse -10.30 and so on. i want to use it numbers in formula later.
thank you in advance!!!
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: cut and convert string index to number

Post by balala »

nikko wrote: March 31st, 2021, 1:37 pm i have question how to use values where is -09:30 in this string 2021-03-31T03:47:23.768-09:30 ? it can be + or - before that numbers and i would like to cut it and convert to integer. i would like it to be in format -9.30 in this case and if not 0 first then of corse -10.30 and so on. i want to use it numbers in formula later.
Try the following substitution, which has to be added (along with the RegExpSubstitute=1 option), to the measure which is returning the above date and time string. Not knowing the measure you are using, I used an extremely simple String measure, but in reality I suppose it is a (probably) WebParser measure?

Code: Select all

[MeasureString]
Measure=String
String=2021-03-31T03:47:23.768-09:30
RegExpSubstitute=1
Substitute="^.*([-|+]\d{2}:\d{2})$":"\1",":":"."

[MeasureCalc]
Measure=Calc
Formula=( [MeasureString] + 1 )
DynamicVariables=1
As you can see the number returned by the [MeasureString] measure can be used into a Calc measure for instance to make a calculation (here I added 1 to it).
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: cut and convert string index to number

Post by nikko »

balala wrote: March 31st, 2021, 5:10 pm Try the following substitution, which has to be added (along with the RegExpSubstitute=1 option), to the measure which is returning the above date and time string. Not knowing the measure you are using, I used an extremely simple String measure, but in reality I suppose it is a (probably) WebParser measure?

Code: Select all

[MeasureString]
Measure=String
String=2021-03-31T03:47:23.768-09:30
RegExpSubstitute=1
Substitute="^.*([-|+]\d{2}:\d{2})$":"\1",":":"."

[MeasureCalc]
Measure=Calc
Formula=( [MeasureString] + 1 )
DynamicVariables=1
As you can see the number returned by the [MeasureString] measure can be used into a Calc measure for instance to make a calculation (here I added 1 to it).
yes it is regexp.
okay and how to calculate this to get exact result in hours and minutes? 15mins is 25%, 30mins=50%..
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: cut and convert string index to number

Post by balala »

nikko wrote: March 31st, 2021, 6:26 pm how to calculate this to get exact result in hours and minutes? 15mins is 25%, 30mins=50%..
For instance this way:

Code: Select all

[MeasureCalc]
Measure=Calc
Formula=(( Trunc ( [MeasureString] )) + (( Frac ( [MeasureString] )) / 0.60 ))
DynamicVariables=1
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: cut and convert string index to number

Post by nikko »

balala wrote: March 31st, 2021, 7:28 pm For instance this way:

Code: Select all

[MeasureCalc]
Measure=Calc
Formula=(( Trunc ( [MeasureString] )) + (( Frac ( [MeasureString] )) / 0.60 ))
DynamicVariables=1
it works but there is extra calc operation error for this formula.
User avatar
balala
Rainmeter Sage
Posts: 16142
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: cut and convert string index to number

Post by balala »

nikko wrote: March 31st, 2021, 7:56 pm it works but there is extra calc operation error for this formula.
Probably the measure which gets the value which has to be converted to decimal number is a WebParser measure (the measure coresponding to [MeasureString] in the above code). Such a measure doesn't have a value when you're refreshing the skin, it takes a few moments until it gets the result. In meantime the Calc measure ([MeasureCalc] in this case) tries to make the needed calculations, but the [MeasureString] measure not having a value, it fails, returning the error message.
The solution is pretty simple: disable the [MeasureCalc] measure (by adding a Hidden=1 option) and add the following FinishAction option to the parent WebParser measure: FinishAction=[!EnableMeasure "MeasureCalc"][!UpdateMeasure "MeasureCalc"]. Take care to add this FinishAction option not necessarily to the measure which is returning the substituted date / time (unless it's the parent measure), but to the parent measure.

NOTE: would be much easier for me to help if I'd have the code. Please whenever are you asking for help, post the code, not just general questions, because this complicates things too much: https://forum.rainmeter.net/viewtopic.php?f=5&t=28421#p148358