It is currently May 6th, 2024, 9:50 am
How to count letters from a string?
-
- Posts: 8
- Joined: October 9th, 2010, 2:34 pm
How to count letters from a string?
Hi guys, I was just wondering if there was any way of counting how many characters are in a string so that they may be used with another measure that only deals with numbers?
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: How to count letters from a string?
Not in any easy way I can think of. It would probably take a Rube Goldberg setup using an addon that you pass the string to, which can count the chars and write to a variable in the .ini using !RainmeterWriteKeyValue.
Rainmeter itself does not expose any functions to determine the number of characters in a string.
Rainmeter itself does not expose any functions to determine the number of characters in a string.
-
- Posts: 8
- Joined: October 9th, 2010, 2:34 pm
Re: How to count letters from a string?
What if I used substitute to make all of the characters '1'? Would there be anyway of using Calc to add them all together? i.e. 11111 = 5?
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: How to count letters from a string?
Not really. 11111 = Eleven thousand, one hundred and eleven.Takinu wrote:What if I used substitute to make all of the characters '1'? Would there be anyway of using Calc to add them all together? i.e. 11111 = 5?
There may be some trick I am missing, But most of what I can envision would just be horrible kludges using just stupid amounts of conditional statements to enable and disable measures or who knows what.
-
- Posts: 8
- Joined: October 9th, 2010, 2:34 pm
Re: How to count letters from a string?
Dang.jsmorley wrote: Not really. 11111 = Eleven thousand, one hundred and eleven.
There may be some trick I am missing, But most of what I can envision would just be horrible kludges using just stupid amounts of conditional statements to enable and disable measures or who knows what.
-
- Developer
- Posts: 98
- Joined: August 6th, 2009, 3:03 pm
Re: How to count letters from a string?
What would happen if you substituted all characters with "1+".
it could potentially work mayhaps.
it could potentially work mayhaps.
-
- Posts: 8
- Joined: October 9th, 2010, 2:34 pm
Re: How to count letters from a string?
Nope. T_TMattKing wrote:What would happen if you substituted all characters with "1+".
it could potentially work mayhaps.
-
- Rainmeter Sage
- Posts: 642
- Joined: July 19th, 2009, 5:59 am
- Location: Montreal, QC, Canada
Re: How to count letters from a string?
That would work, but it would be a pain in the ass to write that substitute. Also, in the calc you would need to make sure you added a zero after the measure name because the string after substitution is going to end with a '+'. Another way to do it would be to convert every character to a zero, then use a calc with Formula=LOG(1[ConvertedMeasure]). I wrote up a short skin using both methods:
And "Text.txt" contains:
I wish there were a better way than those, but I can't think of one.
Code: Select all
[Rainmeter]
DynamicWindowSize=1
[GetString]
Measure=Plugin
Plugin=Plugins/WebParser.dll
URL=file://#CURRENTPATH#/text.txt
RegExp=(?siU)<word>(.*)</word>
StringIndex=1
[GetCount]
Measure=Plugin
Plugin=Plugins/WebParser.dll
URL=[GetString]
StringIndex=1
Substitute="H":"0","E":"0","L":"0","O":"0"," ":"0","T":"0","R":"0"
[GetCount2]
Measure=Plugin
Plugin=Plugins/WebParser.dll
URL=[GetString]
StringIndex=1
Substitute="H":"1+","E":"1+","L":"1+","O":"1+"," ":"1+","T":"1+","R":"1+"
[Count]
Measure=Calc
Formula=LOG(1[GetCount])
DynamicVariables=1
[Count2]
Measure=Calc
Formula=[GetCount2]0
DynamicVariables=1
[String]
Meter=String
MeasureName=GetString
MeasureName2=GetCount
MeasureName3=Count
MeasureName4=GetCount2
MeasureName5=Count2
Text=%1#CRLF#%2#CRLF#%3#CRLF#%4#CRLF#%5
SolidColor=ffffff
Code: Select all
<word>HELLO THERE</word>
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: How to count letters from a string?
Well here is one way, using a little addon...
Get this .rmskin and double click it to install it.
It will load this skin, which will call an addon called "CountChars" that will be installed in your Addons folder under \CountChars.
So every 20 seconds (UpdateRate) it will get the string in the local text file "String2Count.txt" and will return the number of chars in the dynamic variable #StringLen#
Test it by opening String2Count.txt and changing the text. Don't change the <1> or </1> unless you also change the RegExp=
So this is a quick and dirty using WebParser, but there is no reason why you can't pass that addon the value of a measure of any kind with [MeasureName], and it should work.
Get this .rmskin and double click it to install it.
It will load this skin, which will call an addon called "CountChars" that will be installed in your Addons folder under \CountChars.
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
[Variables]
StringLen=1
[MeasureGetString]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=20
URL=file://#CURRENTPATH#String2Count.txt
RegExp="(?siU)<1>(.*)</1>"
StringIndex=1
FinishAction=!Execute ["#ADDONSPATH#\CountChars\CountChars.exe" "[MeasureGetString]" "StringLen" "#CURRENTCONFIG#"]
[MeterValue]
Meter=String
MeasureName=MeasureGetString
FontSize=15
FontColor=255,255,255,255
Text=String: %1
[MeterCount]
Meter=String
Y=R
FontSize=15
FontColor=255,255,255,255
Text=Count: #StringLen#
DynamicVariables=1
Test it by opening String2Count.txt and changing the text. Don't change the <1> or </1> unless you also change the RegExp=
So this is a quick and dirty using WebParser, but there is no reason why you can't pass that addon the value of a measure of any kind with [MeasureName], and it should work.
You do not have the required permissions to view the files attached to this post.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: How to count letters from a string?
Oh, here is the AutoIt code, so you can see what it is doing...
Code: Select all
#NoTrayIcon
;!RainmeterSetVariable [Variable] [Value] (Config)
;CountChars.exe [Measure] "Variable" "Config"
If $CmdLine[0] <> 3 Then Exit
$Measure2Count = $CmdLine[1]
$Variable = $CmdLine[2]
$Config=$CmdLine[3]
$Count=StringLen($Measure2Count)
ShellExecute("..\..\Rainmeter.exe", "!RainmeterSetVariable " & chr(34) & $Variable & chr(34) & " " & chr(34) & $Count & chr(34) & " " & chr(34) & $Config & chr(34))