之前有一個C#的版本....
剛好有用VB.NET的所以就換了VB的版本
這個都是參考人家的東東
不過我忘了是在哪看到的了
Private Function SmartTrim(ByVal value As String, ByVal startIndex As Integer, _
ByVal length As Integer) As String
Dim charArray As Char() = value.ToCharArray()
Dim returnValue As String = ""
Dim returnLen As Integer = 0
Dim index As Integer = 0
Dim x As Integer = 0
Do While index < (startIndex + length)
Dim ch As Char = charArray(x)
Dim category As System.Globalization.UnicodeCategory = Char.GetUnicodeCategory(ch)
If category = System.Globalization.UnicodeCategory.OtherLetter Then
' 其他語言文字
index += 2
Else
index += 1
End If
If (index >= (startIndex + 1)) Then
If category = System.Globalization.UnicodeCategory.OtherLetter Then
returnLen += 2
Else
returnLen += 1
End If
If returnLen <= length Then
returnValue = returnValue & ch.ToString()
End If
End If
x += 1
Loop
Return returnValue
End Function
文章標籤
全站熱搜
