Published in: VB.NET
Pad a string with any character up to a fixed length.
''' <summary>Pad an int with an arbitary number of chars</summary> ''' <param name="n">Integer to pad</param> ''' <param name="len">Length of the resulting padded string</param> ''' <param name="c">Char to pad</param> ''' <returns>Padded string</returns> Private Function Pad(ByVal n As Int32, ByVal len As Int32, ByVal c As Char) As String If n > (10^len) Then Return Convert.ToString(n) ElseIf n < (10^len) And n > (10^(len-1)) Then Return Pad(n, len-1, c) Else Dim t As String = Convert.ToString(n) Dim s As String = "" For j As Int32 = 1 To len - t.Length s &= c Next Return s & n End If End Function ''' <summary>Pad an int with an arbitary number of zeros</summary> ''' <param name="n">Integer to pad</param> ''' <param name="len">Length of the resulting padded string</param> ''' <returns>Padded string</returns> Private Function Pad(ByVal n As Int32, ByVal len As Int32) As String Return Pad(n, len, "0"c) End Function
You need to login to post a comment.
