Ability to change case of string in Format()

Propose new features and changes
GeekDude
Posts: 836
Joined: 02 Oct 2013, 22:13

Ability to change case of string in Format()

29 Jan 2015, 23:13

Thus removing the need for StringUpper and StringLower. I'm not sure exactly how it would be put in, but then again I'm not really completely sure of the finer points of using the Format function.
lexikos
Posts: 6042
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Ability to change case of string in Format()

30 Jan 2015, 00:48

I think that 'U' (but not 'u'), 'l', 'L', 't' and 'T' would all be safe to use in a format specifier, as they're currently not recognized. I'll look into feasibility.

Edit: I suppose that would side-step the problem of StrUpper-T vs StrTitle vs StrTitleCase vs StrCase-U/L/T.
User avatar
joedf
Posts: 6396
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Ability to change case of string in Format()

30 Jan 2015, 07:37

Hmm good idea
lexikos
Posts: 6042
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Ability to change case of string in Format()

14 Feb 2015, 00:45

It turns out to be fairly easy to do.

Format("{:U}", str) is a bit cumbersome. Any thoughts about the following?

1. Allowing short form. For example, Format("U", str).

It would only affect scripts which do both of the following:
  • Pass a format string which matches a valid format specifier (like "02x"); this implies that the format string does not contain any braces, since braces aren't valid inside a format specifier.
  • Pass a second parameter.

2. Allowing the colon to be omitted, as in Format("0x{x}", dec). If it ever becomes possible to supply values via named parameters or an object, one would need to use {name:} rather than {name}.

3. Changing the behaviour of the # prefix to match AutoHotkey's normal hexadecimal formatting, so that one can use Format("#x", dec) rather than Format("0x{:x}", dec). Currently Format("{:#05x}", dec) can produce 0xnnn (if non-zero) or 00000, which is a little odd. The current behaviour was chosen for simplicity (i.e. the formatting of the number is done entirely by the C runtime).

Alternatively, a new type specifier could be added consistent with SetFormat: h or H.
User avatar
joedf
Posts: 6396
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Ability to change case of string in Format()

14 Feb 2015, 07:35

Huh?
I thought they were all added in already...
I thought it was like a sprintf wrapper.. :P
From the good old K&R book:
d,i,o,x,X,u,c,s,f,e,E,g,G,p,n,%
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Ability to change case of string in Format()

14 Feb 2015, 10:00

@joedf, I think lexikos is talking about having {, }, : as optional for format placeholders.
@lexikos, though convenient, if short form is allowed, it might confuse some users(e.g.: similar to that of auto-concat vs concat(.), := vs =) . Especially when they see different scripts with others using the formal form({:}) and the others using the short form.
User avatar
joedf
Posts: 6396
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Ability to change case of string in Format()

14 Feb 2015, 13:21

+1
lexikos
Posts: 6042
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Ability to change case of string in Format()

14 Feb 2015, 18:06

This is not on the level of := vs =, or expressions vs commands. It's more like KeyWait key vs Send {key}, or Send x vs Send {x}. Much more limited in scope.

The format strings are quite cryptic, and will hardly be understood without reading the manual, unless one is already familiar with printf format specifiers, in which case it should be easy to recognize with or without braces.

Do you think that Format("{:02x}", num) is inherently less confusing than Format("02x", num)? I don't. Once one understands the format specifiers, it should be fairly obvious, upon seeing code with and without braces, that the braces are optional. If in doubt, there's a manual to read.

Btw, I suppose one is analogous to .NET's String.Format(Format, Value, ...) and the other is analogous to Value.ToString(Format).

joedf wrote:I thought they were all added in already...
Your post makes no sense. Did you read the thread?
joedf wrote:+1
What are you agreeing with?
User avatar
joedf
Posts: 6396
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Ability to change case of string in Format()

14 Feb 2015, 20:06

About the possibility of confusion

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 4 guests