It is currently April 23rd, 2024, 12:06 pm

Text limit

Get help with installing and using Rainmeter.
Majikaru
Posts: 2
Joined: November 11th, 2019, 7:06 pm

Text limit

Post by Majikaru »

Hi, I'm trying to limit text length by character count, what would the code be for that?

For example, I have a date skin I want to limit to 3 characters so only Mon, Tue, Wed, ETC would show instead of the full text.

Thanks!
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Text limit

Post by jsmorley »

I would use a regular expression substitute for this:

https://docs.rainmeter.net/manual/measures/general-options/substitute/
https://docs.rainmeter.net/manual/measures/general-options/substitute/#RegExpSubstitute

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureString]
Measure=String
String=tuesday
RegExpSubstitute=1
Substitute="^([\w]{3}).*$":"\1"

[MeterString]
Meter=String
MeasureName=MeasureString
StringCase=Proper
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

1.png

"^([\w]{3}).*$":"\1"

Start at the beginning ^ of the string and then start capturing ( a character set of "word" characters [\w]. Limit the capture to exactly 3 characters {3}, then end the capture ). Skip .* all characters until the end $ of the string. Replace the entire string with the first (and in this case only) capture \1.

The "word" [\w] character set definition includes all letters, numbers and punctuation. It will not include spaces, tabs, or linefeeds.
You do not have the required permissions to view the files attached to this post.
Majikaru
Posts: 2
Joined: November 11th, 2019, 7:06 pm

Re: Text limit

Post by Majikaru »

Wow, quick response. It worked, Thanks!
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Text limit

Post by jsmorley »

Glad to help.