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!
It is currently April 23rd, 2024, 12:06 pm
Text limit
-
- Posts: 2
- Joined: November 11th, 2019, 7:06 pm
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Text limit
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
"^([\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.
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
"^([\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.
-
- Posts: 2
- Joined: November 11th, 2019, 7:06 pm
Re: Text limit
Wow, quick response. It worked, Thanks!
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA