'
截取固定长的字符串(双字节的计2位)
' (字符串,ASC码长度,是否显示点号)
Function mySubString() Function mySubString(ByVal stringToSub As String, ByVal length As Integer, Optional ByVal isShowingDot As Integer = True)
Dim regex As Regex = New Regex("[^\x00-\xff]", RegexOptions.Compiled)
Dim stringChar As Char() = stringToSub.ToCharArray()
Dim sb As StringBuilder = New StringBuilder
Dim nLength As Integer = 0
Dim i As Integer
For i = 0 To stringChar.Length - 1
If (regex.IsMatch((stringChar(i)).ToString())) Then
sb.Append(stringChar(i))
nLength += 2
Else
sb.Append(stringChar(i))
nLength = nLength + 1
End If
If (nLength > length) Then
Exit For
End If
Next i
If isShowingDot = True And Trim(stringToSub) <> Trim(sb.ToString) Then
Return sb.ToString() + " "
Else
Return sb.ToString()
End If
End Function
' (字符串,ASC码长度,是否显示点号)
Function mySubString() Function mySubString(ByVal stringToSub As String, ByVal length As Integer, Optional ByVal isShowingDot As Integer = True)
Dim regex As Regex = New Regex("[^\x00-\xff]", RegexOptions.Compiled)
Dim stringChar As Char() = stringToSub.ToCharArray()
Dim sb As StringBuilder = New StringBuilder
Dim nLength As Integer = 0
Dim i As Integer
For i = 0 To stringChar.Length - 1
If (regex.IsMatch((stringChar(i)).ToString())) Then
sb.Append(stringChar(i))
nLength += 2
Else
sb.Append(stringChar(i))
nLength = nLength + 1
End If
If (nLength > length) Then
Exit For
End If
Next i
If isShowingDot = True And Trim(stringToSub) <> Trim(sb.ToString) Then
Return sb.ToString() + " "
Else
Return sb.ToString()
End If
End Function