Jump to content

How do I pad a string?


 Share

Recommended Posts

Please elaborate as i can't understand what do u mean by "Pad"

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

Please elaborate as i can't understand what do u mean by "Pad"

sorry, pad with spaces... It is not perfectly lining up.. but it should.. I edited a few times.

e.g. here is one example padding with '.'

a = b
dexz = f

to

a.......... = b
dexz....... = f
Link to comment
Share on other sites

welll i had that same issue once... i'd suggest using @TAB between them... ie:

a&@TAB&@TAB&@TAB = b
abdj&@TAB&@TAB&@TAB = 5jj

the thing is... some letters are normaly bigger then others which causes issues even while using @TAB...

EDIT> forgot to mention that some control's and window's spaces are different as well... thus even some more problems...

If it's important enough just use a listview... the new beta made these quite easy to use!

Edited by Armand

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

welll i had that same issue once... i'd suggest using @TAB between them... ie:

a&@TAB&@TAB&@TAB = b
abdj&@TAB&@TAB&@TAB = 5jj

the thing is... some letters are normaly bigger then others which causes issues even while using @TAB...

EDIT> forgot to mention that some control's and window's spaces are different as well... thus even some more problems...

If it's important enough just use a listview... the new beta made these quite easy to use!

ok, thanks... I will consider this thread "sovled" but if anyone does know of an functions or combination of functions that can help me do a real pad, then let me know... I mean just e.g. pad($s, 20, ".") would put up to 20 dots... hmm I'm getting lazy, I guess I could've written a function already in the amount of time it took me to write this :D
Link to comment
Share on other sites

ok, thanks... I will consider this thread "sovled" but if anyone does know of an functions or combination of functions that can help me do a real pad, then let me know... I mean just e.g. pad($s, 20, ".") would put up to 20 dots... hmm I'm getting lazy, I guess I could've written a function already in the amount of time it took me to write this :D

I was simply talking about dealing with strings... not GUI

Link to comment
Share on other sites

Maybe This will work, it has for me.

Thanks

StringFormat("[%10s]", $s) & @CRLF); // right-justification with spaces

StringFormat("[%-10s]", $s) & @CRLF); // left-justification with spaces

StringFormat("[%010s]", $s) & @CRLF); // zero-padding works on strings too

StringFormat("[%10.10s]", $t) & @CRLF); // left-justification but with a cutoff of 10 characters

Link to comment
Share on other sites

Other way would be

_StringRepeat(' ', 50 - StringLen($yourString))

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Like this:

#include <String.au3>
Global $a = "Hello"

ConsoleWrite(_stringPad($a, '.') & @CRLF)
ConsoleWrite(_stringPad($a, '#', 10, 0) & @CRLF)

Func _stringPad($string, $pad = ' ', $count = 10, $opt = 1)
    If $opt = 1 Then
        Return $string & _StringRepeat($pad, $count - StringLen($string))
    Else
        Return _StringRepeat($pad, $count - StringLen($string)) & $string
    EndIf
EndFunc   ;==>_stringPad

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...