It is currently April 27th, 2024, 2:43 pm

Leading Zero

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

xenium wrote: December 28th, 2018, 7:47 pm Hi,

I have a webparser measure that displays time in a format like this :
23: 00
00: 00
01: 00

How do I use substitute to remove leading zero,to display time in format:
23:00
0: 00
1: 00

Thanks
Add the following two options to the WebParser measure:

Code: Select all

RegExpSubstitute=1
Substitute="^0(.):(..)$":"\1:\2"
I suppose there is no space between the colon and the minutes. In five of the above examples you have a such space, in one you haven't. If there is a such space, add it to the above Substitute option as well.
User avatar
xenium
Posts: 868
Joined: January 4th, 2018, 9:52 pm

Re: Leading Zero

Post by xenium »

balala wrote: December 28th, 2018, 8:44 pm Add the following two options to the WebParser measure:

Code: Select all

RegExpSubstitute=1
Substitute="^0(.):(..)$":"\1:\2"
I suppose there is no space between the colon and the minutes. In five of the above examples you have a such space, in one you haven't. If there is a such space, add it to the above Substitute option as well.
:great:
Thank you very much !
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: Leading Zero

Post by RicardoTM »

balala wrote: December 28th, 2018, 8:44 pm
Add the following two options to the WebParser measure:

Code: Select all

RegExpSubstitute=1
Substitute="^0(.):(..)$":"\1:\2"
I suppose there is no space between the colon and the minutes. In five of the above examples you have a such space, in one you haven't. If there is a such space, add it to the above Substitute option as well.
Hey balala, Do you have another one but for RGB strings?

like:

125,25,5 to 125,025,005
255,135,35 to 255,135,035
0,0,0 to 000,000,000

TIA.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Leading Zero

Post by Yincognito »

RicardoTM wrote: April 10th, 2024, 1:52 am Hey balala, Do you have another one but for RGB strings?

like:

125,25,5 to 125,025,005
255,135,35 to 255,135,035
0,0,0 to 000,000,000

TIA.
I'm not balala, but since I saw this, you can try...

Code: Select all

RegExpSubstitute=1
Substitute="(\d+)":"00\1","\d+(\d{3})":"\1"
This is untested, but it should work for any integer in a string, assuming that sufficient leading zeros are added in the 1st part of the Substitute, and that the desired number of digits are kept in its 2nd part.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

RicardoTM wrote: April 10th, 2024, 1:52 am Hey balala, Do you have another one but for RGB strings?
Yincognioto posted the solution, so I don't, instead just asking: even if possible, why to do this? I mean that I don't see a reason why would you like to do such a substitution. Maybe I am missing something, but in my opinion at least doesn't really make sense. However as you saw above in Yincognito's reply, this is perfectly possible, if needed.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Leading Zero

Post by Yincognito »

balala wrote: April 10th, 2024, 3:03 pm I mean that I don't see a reason why would you like to do such a substitution.
I suppose one reason could be that in some fonts, having the same number of digits for two such RGB sets would "align" them with one another (e.g. red value under red value, and so on). Just guessing, could be some other more "functional" reason for it. :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

Yincognito wrote: April 10th, 2024, 3:28 pm I suppose one reason could be that in some fonts, having the same number of digits for two such RGB sets would "align" them with one another (e.g. red value under red value, and so on).
Good point, didn't think to this.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Leading Zero

Post by Yincognito »

balala wrote: April 10th, 2024, 3:36 pm Good point, didn't think to this.
Yeah, when such parts are displayed in a single meter (or multiple, if one below the others), it often looks better than having the string all over the place (even if centered). ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
RicardoTM
Posts: 268
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: Leading Zero

Post by RicardoTM »

Yincognito wrote: April 10th, 2024, 8:29 am I'm not balala, but since I saw this, you can try...

Code: Select all

RegExpSubstitute=1
Substitute="(\d+)":"00\1","\d+(\d{3})":"\1"
This is untested, but it should work for any integer in a string, assuming that sufficient leading zeros are added in the 1st part of the Substitute, and that the desired number of digits are kept in its 2nd part.
Thanks Yin, it works 👍🏼
balala wrote: April 10th, 2024, 3:03 pm I don't see a reason why would you like to do such a substitution. Maybe I am missing something, but in my opinion at least doesn't really make sense.
As Yin already mentioned. It's for design and alignment reasons. I'm making a color selector and I don't like it when the numbers are drifting and changing number of characters. So i'm using a Monospaced font to avoid it, and the substitution to ensure it always takes the same space. You'll see what I'm talking about when I release it soon, it's almost finished.