Ability to change case of string in Format()
Ability to change case of string in Format()
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.
Re: Ability to change case of string in Format()
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.
Edit: I suppose that would side-step the problem of StrUpper-T vs StrTitle vs StrTitleCase vs StrCase-U/L/T.
Re: Ability to change case of string in Format()
Hmm good idea
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Ability to change case of string in Format()
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:
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.
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.
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.
Re: Ability to change case of string in Format()
Huh?
I thought they were all added in already...
I thought it was like a sprintf wrapper..
From the good old K&R book:
d,i,o,x,X,u,c,s,f,e,E,g,G,p,n,%
I thought they were all added in already...
I thought it was like a sprintf wrapper..
From the good old K&R book:
d,i,o,x,X,u,c,s,f,e,E,g,G,p,n,%
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Ability to change case of string in Format()
@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.
@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.
Re: Ability to change case of string in Format()
+1
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Ability to change case of string in Format()
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).
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).
Your post makes no sense. Did you read the thread?joedf wrote:I thought they were all added in already...
What are you agreeing with?joedf wrote:+1
Re: Ability to change case of string in Format()
About the possibility of confusion
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Who is online
Users browsing this forum: No registered users and 57 guests