equivalent of istitle() in python? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shpj123
Posts: 4
Joined: 21 Sep 2022, 03:16

equivalent of istitle() in python?

21 Sep 2022, 14:04

Hi everyone,
I'm working on a script to loop through different cases with the same hotkey.
For that I need to detect the case a string is in.
I've googled a lot, but I failed to find a way in autohotkey to check for title case, something like the istitle() in python.

E.g.:
'This Is @ Symbol. >> true
99 Is A "Number"! >> true
PYTHON >> false


I will be really glad for any suggestions.
Best,
PJ
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: equivalent of istitle() in python?

21 Sep 2022, 14:17

I'd guess you've to go with RegEx… . A quite crude workaround would be probably a construct of SubStr(), if var is lower/upper
shpj123
Posts: 4
Joined: 21 Sep 2022, 03:16

Re: equivalent of istitle() in python?  Topic is solved

21 Sep 2022, 14:47

BoBo wrote:
21 Sep 2022, 14:17
I'd guess you've to go with RegEx… . A quite crude workaround would be probably a construct of SubStr(), if var is lower/upper
thx for the quick reply!
I've got a better solution now with the help from discord:

Code: Select all

isTitleCase(param_input) {
    StringUpper, OutputVar, % param_input, T
    if (OutputVar == param_input) {
        return true
    }
    return false
}
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: equivalent of istitle() in python?

21 Sep 2022, 16:25

Example using Format()

Code: Select all

isTitleCase(param_input) {
    if (Format("{:T}", param_input) == param_input)
        return true
    return false
}
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: equivalent of istitle() in python?

21 Sep 2022, 19:21

shorter:

Code: Select all

isTitleCase(param_input) {
    return Format("{:T}", param_input) == param_input
}
and marginally faster (but not faster than the Stringupper one...)
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 390 guests