String
Public Class Ustringclass ustring
Private Shared gencoding as System.Text.Encoding = System.Text.Encoding.GetEncoding ("GB2312")
Public Shared Property Encoding () 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 Ch AR) 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
Test comparison:
Private Sub Toolstripbutton6_click () Sub Toolstripbutton6_click (ByVal sender as System.Object, ByVal e As System.EventArgs) Handles Toolstripbutton6.click
Dim tmp as String = "China Chinese"
Console.WriteLine (LzmTW.uString.Encoding.EncodingName)
Console.WriteLine (LzmTW.uString.Length (TMP))
Console.WriteLine (TMP. Length)
Console.WriteLine (TMP. Substring (0, 2))
Console.WriteLine (LzmTW.uString.SubString (TMP, 0, 2))
Console.WriteLine (New String ("*" C, 20))
Console.WriteLine (LzmTW.uString.PadLeft (TMP, "*" C))
Console.WriteLine (TMP. PadLeft ("*" C))
Console.WriteLine (LzmTW.uString.PadRight (TMP, "*" C))
Console.WriteLine (TMP. PadRight ("*" C))
Console.WriteLine (LzmTW.uString.PadLeft (TMP, 20))
Console.WriteLine (TMP. PadLeft (20))
Console.WriteLine (LzmTW.uString.PadRight (TMP, 20))
Console.WriteLine (TMP. PadRight (20))
End Sub