formating numbers with padded spaces

pcbtmr

Member
Licensed User
Longtime User
I understand that Numberformat will pad zeros to fulfill the minimum integers spec. Is there a simple way to pad spaces rather than 0?
Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Log(PadNumberWithSpaces(10203, 10))
End Sub
Sub PadNumberWithSpaces(Number As Int, NumberOfSpaces)
   If Number = 0 Then Return "0"
   Dim n, res As String
   n = NumberFormat2(Number, NumberOfSpaces, 0,0, False)
   For i = 0 To n.Length - 1
      If n.CharAt(i) = 0 Then
         res = res & " "
      Else
         res = res & n.SubString(i)
         Return res
      End If
   Next
   Return res
End Sub

You will probably want to use a monospace font.
 
Upvote 0
Top