Jump to content
Sign in to follow this  
ycomp

How do I pad a string?

Recommended Posts

ycomp

Hi,

how would I pad a string so everything lines up?

e.g.

x+y = z
x+y+q = well, not z

so I would like 2 strings:

x+y  = z
x+y+q = well, not z

thanks

Edited by ycomp

Share this post


Link to post
Share on other sites
Armand

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 ?!

Share this post


Link to post
Share on other sites
ycomp

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

Share this post


Link to post
Share on other sites
Armand

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 ?!

Share this post


Link to post
Share on other sites
weaponx

You need to clarify, are you talking about fixed width fonts in the forum codebox? Or are you talking about the AutoIt MessageBox()?

Share this post


Link to post
Share on other sites
ycomp

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

Share this post


Link to post
Share on other sites
ycomp

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

Share this post


Link to post
Share on other sites
xroot

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

Share this post


Link to post
Share on other sites
Xenobiologist

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

Share this post


Link to post
Share on other sites
Xenobiologist

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

Share this post


Link to post
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
Sign in to follow this  

×