how to use padright and padleft to aligne text in 2 columns ?

P

Pascal

hello

i try to use padright and padleft to beautify the aspect of my prints. I 'd
like the text to be print in two columns but i don't know the size of each
string before (because they are randomly generated) I thought that padright
complete the lenght of a string to the size noticed as a variable like
padright (50) if the string is 35 of lenght so padright add 15 to fit to
the given size of 50. But it seems it doesn't work like this ? Can some one
tell what doesn't work in this code ?
m_Paragraphs = New Collection

Dim mtEspaces As String = " = .......... "

For i As Integer = 1 To 20

Dim myStr1 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like 9 352

Dim myStr2 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like 9 352

m_Paragraphs.Add(New ParagraphInfo(11, i.ToString + ") ".PadRight(5) &
myStr1.PadRight(5) & mtEspaces.PadRight(50) & myStr2.PadRight(5) &
mtEspaces))

m_Paragraphs.Add(New ParagraphInfo(9, vbCrLf))

Next

the string are not aligned in two columns....

thanks for help
pascal

http://www.scalpa.info
 
R

Rick

I didn't look at your code carefully, but you have to use a monospaced font
for your concept to work in general. Courier is an example.

Other fonts have varing character widths so a space is less width than a
"W".

You might also try to imbed a tab character (Chr(9)) and see if that works.

Rick
 
P

Pascal

thank you, you were right and also i have to calculate the longest string
before to apply a padright lenght according to this variable

thank again
pascal
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Pascal said:
hello

i try to use padright and padleft to beautify the aspect of my prints. I 'd
like the text to be print in two columns but i don't know the size of each
string before (because they are randomly generated) I thought that padright
complete the lenght of a string to the size noticed as a variable like
padright (50) if the string is 35 of lenght so padright add 15 to fit to
the given size of 50. But it seems it doesn't work like this ? Can some one
tell what doesn't work in this code ?
m_Paragraphs = New Collection

Dim mtEspaces As String = " = .......... "

For i As Integer = 1 To 20

Dim myStr1 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like 9 352

Dim myStr2 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like 9 352

m_Paragraphs.Add(New ParagraphInfo(11, i.ToString + ") ".PadRight(5) &
myStr1.PadRight(5) & mtEspaces.PadRight(50) & myStr2.PadRight(5) &
mtEspaces))

m_Paragraphs.Add(New ParagraphInfo(9, vbCrLf))

Next

the string are not aligned in two columns....

thanks for help
pascal

http://www.scalpa.info

The expression i.ToString + ") ".PadRight(5) always creates the same
result, namely the same as i.ToString + ") ". If you want to pad the
string including the number, you have to add parentheses so that the
entire string is padded, not just the second string:

(i.ToString + ") ").PadRight(5)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top