网学网为需要ASP.net的朋友们搜集整理了HOW TO:操作定长字符串相关资料,希望对各位网友有所帮助!
Private Shared gEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("GB2312") Public Shared Property Encoding()Property Encoding() As System.Text.Encoding
Get
Return gEncoding
End Get
Set(ByVal value As System.Text.Encoding)
gEncoding = value
End Set
End Property
Public Shared Function Length()Function Length(ByVal s As String) As Integer
Return gEncoding.GetByteCount(s)
End Function
Public Shared Function PadLeft()Function PadLeft(ByVal s As String, ByVal totalWidth As Integer, ByVal paddingChar As Char) As String
Return s.PadLeft(totalWidth + s.Length - Length(s), paddingChar)
End Function
Public Shared Function PadLeft()Function PadLeft(ByVal s As String, ByVal totalWidth As Integer) As String
Return s.PadLeft(totalWidth + s.Length - Length(s))
End Function
Public Shared Function PadRight()Function PadRight(ByVal s As String, ByVal totalWidth As Integer, ByVal paddingChar As Char) As String
Return s.PadRight(totalWidth + s.Length - Length(s), paddingChar)
End Function
Public Shared Function PadRight()Function PadRight(ByVal s As String, ByVal totalWidth As Integer) As String
Return s.PadRight(totalWidth + s.Length - Length(s))
End Function
Public Shared Function SubString()Function SubString(ByVal Line As String, ByVal Index As Integer, ByVal Length As Integer) As String
Return gEncoding.GetString(gEncoding.GetBytes(Line), Index, Length)
End Function
End Class