Android Question [SOLVED] Fill string variables with asterisks

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello friends

I want to know how it is possible to fill a string type variable with asterisks, in VB.Net I do it with this code:

B4X:
Dim Pass As String = "Hello"
Dim MyString As String = Pass.PadLeft (10, "*")
Dim MyString1 As String = Pass.PadRight (10, "*")


It is shown for the variable MyString: **** Hello and for the variable MyString1: Hello *****

You can do this yourself using B4A

Thank you so much.
 

LucaMs

Expert
Licensed User
Longtime User
B4X:
Public Const PAD_LEFT As Int = 1
Public Const PAD_RIGHT As Int = 2


Public Sub PadStr(Text As String, Position As Int, NumOfExtraChars As Int, ExtraChar As String) As String
   Dim Result As String
 
   Dim sb As StringBuilder
   sb.Initialize
   For i = 1 To NumOfExtraChars
       sb.Append(ExtraChar)
   Next
 
   If Position = PAD_LEFT Then
       Result = sb.ToString & Text
   Else If Position = PAD_RIGHT Then
       Result = Text & sb.ToString
   End If
 
   Return Result
End Sub
 
Last edited:
Upvote 0
Top