Add spaces

Sytek

Active Member
Licensed User
Longtime User
Hi!
I think this is an easy one; But I didn't find it.
I need to add some spaces.

I have this variables .
xy="1234"
xz="5678"

I need to print them like this
xy plus this would be let's say 10 spaces plus xz

Thank's in advance!
 

aaronk

Well-Known Member
Licensed User
Longtime User
Maybe something like this?

B4X:
dim xy, xz, xyz as string

   xy="1234"
   xz="5678"

   xyz = xy & "          " & xz

Log(xyz) ' returns 1234          5678   (with 10 spaces)
 
Upvote 0

Sytek

Active Member
Licensed User
Longtime User
No, I need to print the spaces like this

B4X:
dim xy, xz, xyz as string

   xy="1234"
   xz="5678"

   xyz = xy &replicate(" ",(30-xy.lenght))& xz
...Where replicate would be the command/function to add the spaces.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Something like this ???

B4X:
dim xy, xz, xyz as string

   xy="1234"
   xz="5678"

   xyz = xy & Space(30) & xz


Sub Space(HM As Int) As String   
   
   Dim retStr As String
   retStr = ""
   Do While Len(retStr) < HM
      retStr = retStr & " "
   Loop
   Return retStr
   
End Sub

Cheers mj
 
Upvote 0

Sytek

Active Member
Licensed User
Longtime User
Yes mj something like that; Thank's

...I have another one.


B4X:
 xy="1234"
   xz="5678"

   xyz = xy & replicate(" ",(30-xy.Length)) & xz


Sub replicate(charadd As String, totcharadd As Int)
   Private totspaces As String
   For i = 1 To totcharadd
      totspaces = totspaces&charadd
   Next
'   Msgbox(totspaces&totspaces.Length,"tot spaces")
   Return totspaces
End Sub
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
B4X:
dim nSpace as int

xy="1234"
xz="5678"

nSpace = 30 - xy.Lenght

xyz = xy & replicate(" ",nSpace) & xz


Sub replicate(charadd As String, totcharadd As Int)
   Private totspaces As String
   For i = 1 To totcharadd
      totspaces = totspaces&charadd
   Next
'   Msgbox(totspaces&totspaces.Length,"tot spaces")
   Return totspaces
End Sub

Cheers mj
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
B4X:
S="                              "
Xy & s.substring(xy.length) & xz
This will error if xy contains 30 or more chars, an 'if' can be used.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…