-
StackOverflow 文档
-
Visual Basic .NET Language 教程
-
扩展方法
-
填充数字
Public Module Usage
Public Sub LikeThis()
Dim iCount As Integer
Dim sCount As String
iCount = 245
sCount = iCount.PadLeft(4, "0")
Console.WriteLine(sCount)
Console.ReadKey()
End Sub
End Module
Public Module Padding
<Extension>
Public Function PadLeft(Value As Integer, Length As Integer) As String
Return Value.PadLeft(Length, Space(Length))
End Function
<Extension>
Public Function PadRight(Value As Integer, Length As Integer) As String
Return Value.PadRight(Length, Space(Length))
End Function
<Extension>
Public Function PadLeft(Value As Integer, Length As Integer, Character As Char) As String
Return CStr(Value).PadLeft(Length, Character)
End Function
<Extension>
Public Function PadRight(Value As Integer, Length As Integer, Character As Char) As String
Return CStr(Value).PadRight(Length, Character)
End Function
End Module