It is currently April 26th, 2024, 9:22 am

substitute help with blank/unknown track year

Get help with creating, editing & fixing problems with skins
User avatar
creativegamer_03
Posts: 11
Joined: November 15th, 2021, 5:51 am

substitute help with blank/unknown track year

Post by creativegamer_03 »

While slowly implementing every detail for my screensaver skin with a player on it, I wanted to make sure that the blank/unknown info has a desirable replacement/substitute.
All is well until the Track Year info...

Code: Select all

[mYear]
Measure=NowPlaying
PlayerName=#Player#
PlayerType=Year
Substitute="0":"----"
It works as expected when there is no track year (which returns 0), but fails when there is a track year (replaces all "0" with "----", as stated in the docs, which is disappointing).
Is there a way to make it replace ONLY if the result is just "0"?
rainmeter is just so cool
User avatar
creativegamer_03
Posts: 11
Joined: November 15th, 2021, 5:51 am

Re: substitute help with blank/unknown track year

Post by creativegamer_03 »

actually nvm.. i remembered IfCondition.
rainmeter is just so cool
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: substitute help with blank/unknown track year

Post by eclectic-tech »

creativegamer_03 wrote: November 15th, 2021, 12:40 pm While slowly implementing every detail for my screensaver skin with a player on it, I wanted to make sure that the blank/unknown info has a desirable replacement/substitute.
All is well until the Track Year info...

Code: Select all

[mYear]
Measure=NowPlaying
PlayerName=#Player#
PlayerType=Year
Substitute="0":"----"
It works as expected when there is no track year (which returns 0), but fails when there is a track year (replaces all "0" with "----", as stated in the docs, which is disappointing).
Is there a way to make it replace ONLY if the result is just "0"?
You could use RegExpSubstitute=1 to substitute dashes when zero is the only character in the string, from the beginning(^) to the end($).

Code: Select all

[mYear]
Measure=NowPlaying
PlayerName=#Player#
PlayerType=Year
RegExpSubstitute=1
Substitute="^0$":"----"
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: substitute help with blank/unknown track year

Post by balala »

As an explanation of what is going on and why eclectic-tech's solution does work (because it definitely does), note that if using the original Substitute="0":"----" substitution, every 0 will be replaced by the appropriate string, because the substitution can be applied more times, so all 0s are substituted. If using eclectic-tech's solution (Substitute="^0$":"----"), the substitution goes on ONLY if 0 is the whole string returned by the measure, because as he said, ^ and $ character in the "^0$" part of the option means that between the beginning end the end of the string only one single 0 is allowed. If there is any other character, the substitution doesn't take place.