 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Beastmaster
Joined: 15 Apr 2004 Posts: 181
|
Posted: Thu Sep 30, 2004 8:14 pm Post subject: SetFormat, alpha ... |
|
|
I've to create an order file. Its format is specified, means each field of a data record has a fixed length.
All fields are right-justified. A field can contain numeric or alpha chars.
If numeric chars are used the field has to be padded with zeros. Thats no problem with AHK.
| Quote: | Var = 12
SetFormat, float, 06.0
Var += 0 ; Sets Var to be 000012 |
But with literals there's no such option
| Quote: | Var = ABCDEFGH
SetFormat, alpha, 30
Var += 0 ; Sets Var to be a 30 char string padded with spaces |
Currently it needs some math and a Loop
| Code: | Alphas = ABCDEFGH
FieldLen = 30
StringLen, NumAlphas, Alphas
FieldLen -= %NumAlphas%
Loop, %FieldLen%
{
FileAppend, %A_Space%, C:\MyFile.txt
}
FileAppend, %Alphas%, C:\MyFile.txt |
As there's a slight chance that I've overseen something in the helpfile, I've made that request here - instead on the wish list. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Fri Oct 01, 2004 1:33 am Post subject: |
|
|
I think there is a slightly easier way to do it: | Code: | 30Spaces = x x
StringReplace, 30Spaces, 30Spaces, x,, All
Alphas = ABCDEFGH
AutoTrim, off
PaddedString = %30Spaces%%Alphas%
StringRight, PaddedString, PaddedString, 30
MsgBox, "%PaddedString%" |
You could also do the above with a loop that appends spaces to the beginning of the string based on its initial length. Both of these approaches would probably improve performance and reduce disk activity compared to the one you posted.
Because the need to add padding is somewhat rare, and because there are workarounds, I haven't added this to the wish list yet. If anyone else feels this is a common scripting requirement, feel free to add your vote. |
|
| Back to top |
|
 |
Beastmaster
Joined: 15 Apr 2004 Posts: 181
|
Posted: Fri Oct 01, 2004 9:18 am Post subject: |
|
|
Thx for your support Chris.
Beasty |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|