devxlogo

FormatValue – Format a value in a column of given width

FormatValue – Format a value in a column of given width

Enum FormatColumnAlignment    Left    Center    RightEnd Enum' format a value in a column of given width and with specified alignment' using the specified pad character Function FormatValue(ByVal value As String, ByVal width As Integer, _    ByVal alignment As FormatColumnAlignment, Optional ByVal padchar As Char = _    " "c) As String    Function FormatValue(ByVal value As Object, ByVal width As Integer, _        ByVal alignment As FormatColumnAlignment, Optional ByVal padchar As _        Char = " "c) As String    Dim val As String = value.ToString    Dim len As Integer = val.Length    Select Case alignment        Case FormatColumnAlignment.Left            If len < width Then                val = val.PadRight(width, padchar)            ElseIf len > width Then                val = val.Substring(0, width)            End If        Case FormatColumnAlignment.Center            If len < width Then                Dim charnum As Integer = len + (width - len)  2                val = val.PadLeft(charnum, padchar).PadRight(width, padchar)            ElseIf len > width Then                val = val.Substring((len - width)  2, width)            End If        Case FormatColumnAlignment.Right            If len < width Then                val = val.PadLeft(width, padchar)            ElseIf len > width Then                val = val.Substring(len - width)            End If    End Select    Return valEnd Function

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist