dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB7
Expertise: Intermediate
Jul 13, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


FormatValue - Format a value in a column of given width

Enum FormatColumnAlignment
    Left
    Center
    Right
End 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 val
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date