Stringleft, stringright and substr: ALLOW PAD string

Propose new features and changes
joefiesta
Posts: 126
Joined: 24 Jan 2016, 13:54

Stringleft, stringright and substr: ALLOW PAD string

22 Feb 2018, 10:45

Revised commands STRINGLEFT, STRINGRIGHT and SUBSTR() function.

I would like to see these handle an additional PAD parameter. The new syntax being:

StringLeft, OutputVar, InputVar, Count, Pad
StringRight, OutputVar, InputVar, Count, Pad
NewStr := SubStr(String, StartPos [, Length[,Pad]])


For the commands, when Count is greater than the length of InputVar, OutputVar would be padded to length of Count with n Pad characters. For StringRight, the padding would prefix the output variable.

For Substr(), when StartPos is negative and Length exceeds the number of characters available, the pad would PREFIX the output.

In all these cases, the implemention should probably allow Pad to be a string instead of single character.


Rationale:

a. This would be entirely backward compatible.

b. MSGBOX or a simple GUI of text is rather clumsy when it comes to displaying columnar data because of the inability (as far as I know) of defining tab stop positions. One could easily use a FIXED font and pad data fields to align nicely. (Yes, defining tab stops in GUIs would be awesome, but I suspect well beyond the scope of something so simple as my proposal!)

c. Yes, I can do something like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

  var := "my string"
pad := "---------------------------------------------------------"
padded_var := substr(var . pad, length)

but just the idea of "pad :="--------------------------------------------" is appalling.
User avatar
nnnik
Posts: 2790
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Stringleft, stringright and substr: ALLOW PAD string

22 Feb 2018, 14:02

Isn't Format for formatting strings?
Recommends AHK Studio
joefiesta
Posts: 126
Joined: 24 Jan 2016, 13:54

Re: Stringleft, stringright and substr: ALLOW PAD string

22 Feb 2018, 14:17

I would say NO. I can't figure out how to use format()to pad with anything other than a space. It's documentation only mention padding in 2 regards: (1) padding with spaces and (2) suppressing padding.

In addition, I find the format() function to be absurdly complicated (Yes, if you need all that, there it is), while what I am suggesting is virutally trivial.

If format() can pad with something other than spaces, please show me how. IMHO format() is for numerics and just numerics (although, yes, it can handle strings).
User avatar
nnnik
Posts: 2790
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Stringleft, stringright and substr: ALLOW PAD string

22 Feb 2018, 15:04

Well as far as I understood, the job of StrRight/Left or SubStr is to cut out a part of a string.
How exactly does padding the string with something play a role in that task?
Recommends AHK Studio
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Stringleft, stringright and substr: ALLOW PAD string

22 Feb 2018, 18:09

- I think that the best solution for this problem would be a built-in StrRept function.
- For displaying the text, you could use a custom GUI with an equal-width font, e.g. Courier New, or the Progress command, or change the font for MsgBox temporarily.
[JEE_SystemSetFont function]
GUI COMMANDS: COMPLETE RETHINK - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893&p=131078#p131078
- I'm working on alternatives to the MsgBox/InputBox commands, with added functionality, including specifying a font.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
kczx3
Posts: 542
Joined: 06 Oct 2015, 21:39

Re: Stringleft, stringright and substr: ALLOW PAD string

23 Feb 2018, 21:10

I do agree that the Format function is extremely complicated and hard to understand how to use it.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Stringleft, stringright and substr: ALLOW PAD string

23 Feb 2018, 22:25

- @kczx3: I agree, although with a good list of examples, I don't think it's too bad. See 'FORMAT FUNCTION EXAMPLES' here:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486&p=124372#p124372
- The key things to be aware of are: (1) each {} / {:f} / {n} / {n:f} contains text based on the parameters, the rest of the text is literal text, (2) {n:f}, n is a parameter number, f is a format.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 3 guests