码迷,mamicode.com
首页 > Windows程序 > 详细

【.Net】含Unicode的字符串截断 VB.NET C#

时间:2016-03-15 12:11:16      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

 

 

技术分享
    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
View Code

 

【.Net】含Unicode的字符串截断 VB.NET C#

标签:

原文地址:http://www.cnblogs.com/TonyZhao/p/5278686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!