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!!!
It is currently April 20th, 2024, 5:44 am
cut and convert string index to number
-
- Posts: 44
- Joined: December 5th, 2017, 5:58 pm
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: cut and convert string index to number
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?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.
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
-
- Posts: 44
- Joined: December 5th, 2017, 5:58 pm
Re: cut and convert string index to number
yes it is regexp.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?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).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
okay and how to calculate this to get exact result in hours and minutes? 15mins is 25%, 30mins=50%..
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: cut and convert string index to number
For instance this way:
Code: Select all
[MeasureCalc]
Measure=Calc
Formula=(( Trunc ( [MeasureString] )) + (( Frac ( [MeasureString] )) / 0.60 ))
DynamicVariables=1
-
- Posts: 44
- Joined: December 5th, 2017, 5:58 pm
Re: cut and convert string index to number
it works but there is extra calc operation error for this formula.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
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: cut and convert string index to number
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