.Net含Unicode的字符串截断 VB.NET C#
Posted Tony_Zhao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.Net含Unicode的字符串截断 VB.NET C#相关的知识,希望对你有一定的参考价值。
Function AnsiLeftB(ByVal strArg As String, ByVal arg1 As Integer) As String Dim unicodeEncoding As Encoding = Encoding.GetEncoding("Shift_JIS") Dim unicodeBytes() As Byte = unicodeEncoding.GetBytes(strArg) Dim tempLen As Integer = 0 For i As Integer = 0 To strArg.Length Dim j As Integer = unicodeEncoding.GetByteCount(strArg(i)) If tempLen + j <= arg1 Then tempLen = tempLen + j Else Exit For End If Next Dim tempBytes(tempLen) As Byte Array.Copy(unicodeBytes, tempBytes, tempLen) AnsiLeftB = unicodeEncoding.GetString(tempBytes) End Function
以上是关于.Net含Unicode的字符串截断 VB.NET C#的主要内容,如果未能解决你的问题,请参考以下文章