中英字符判断VB
发布时间:2020-12-17 08:10:34 所属栏目:百科 来源:网络整理
导读:Public Function FirstNoC(ByVal DescStr As String) As Dictionary(Of String,Integer) Dim fNoCIdx As Integer = 0 Dim L = Len(DescStr$) Dim CNum As Integer = 0 Dim fCnum As Integer = 0 Dim idx24 As Integer = 0 For n = 1 To L If Asc(Mid$(DescSt
Public Function FirstNoC(ByVal DescStr As String) As Dictionary(Of String,Integer) Dim fNoCIdx As Integer = 0 Dim L = Len(DescStr$) Dim CNum As Integer = 0 Dim fCnum As Integer = 0 Dim idx24 As Integer = 0 For n = 1 To L If Asc(Mid$(DescStr$,n,1)) < 0 Then fNoCIdx = 0 If n + CNum >= 24 And n + CNum < 26 Then idx24 = n End If CNum += 1 Else If fNoCIdx = 0 Then fNoCIdx = n fCnum = CNum End If End If Next n Dim dic As New Dictionary(Of String,Integer) If idx24 > 0 Then idx24 -= 1 End If If fNoCIdx > 0 Then fNoCIdx -= 1 End If dic.Add("fullLen",L + CNum) dic.Add("fNoCIdx",fNoCIdx) dic.Add("CNum",CNum) dic.Add("fCnum",fCnum) dic.Add("idx24",idx24) FirstNoC = dic End Function Public Function GetMatDesc(ByVal matDesc As String) matDesc = matDesc.Replace(" "," ") '汉字后面第一个字符fNoCIdx,前面有多少汉字fCnum,转码后长度fullLen,汉字数量CNum,Dim dic As Dictionary(Of String,Integer) = FirstNoC(matDesc) '汉字后面第一个字符fNoCIdx Dim fNoCIdx As Integer = dic("fNoCIdx") '转码后总长度fullLen Dim fullLen As Integer = dic("fullLen") '汉字数量CNum Dim CNum As Integer = dic("CNum") '汉字后面第一个字符前汉字数量fCnum Dim fCnum As Integer = dic("fCnum") '前20个字符中的汉字数 Dim idx24 As Integer = dic("idx24") '总长度LenMatDesc Dim LenMatDesc As Integer = matDesc.Length '汉字后面第一个字符前总长度LenMatDesc Dim fClen As Integer = fCnum + fNoCIdx '--------------------------------------- If fullLen = LenMatDesc Then '新增空格隔断 Dim fSpace = matDesc.Split(" ")(0).Length Dim sSpace As Integer = 0 If matDesc.Split(" ").Count > 1 Then sSpace = matDesc.Split(" ")(1).Length End If If fSpace < 24 Then If fSpace + sSpace < 24 Then matDesc = Left(matDesc,fSpace + sSpace + 1) & "<br/>" & Right(matDesc,LenMatDesc - (fSpace + sSpace + 1)) Else matDesc = Left(matDesc,fSpace) & "<br/>" & Right(matDesc,LenMatDesc - fSpace) End If Else matDesc = Left(matDesc,24) & "<br/>" & Right(matDesc,LenMatDesc - 24) End If Else '含有汉字 If fullLen / 2 <> LenMatDesc Then '含有字符 If fNoCIdx < 24 Then If fNoCIdx > 0 Then '新增空格隔断 Dim fSpace = matDesc.Split(" ")(0).Length Dim sSpace As Integer = 0 If matDesc.Split(" ").Count > 1 Then sSpace = matDesc.Split(" ")(1).Length End If If fSpace > fNoCIdx Then If idx24 <> 0 Then If fSpace < idx24 Then If fSpace + sSpace < idx24 Then matDesc = Left(matDesc,fSpace + sSpace) & "<br/>" & Right(matDesc,LenMatDesc - (fSpace + sSpace)) Else If fSpace > idx24 Then matDesc = Left(matDesc,fNoCIdx) & "<br/>" & Right(matDesc,LenMatDesc - fNoCIdx) Else matDesc = Left(matDesc,LenMatDesc - fSpace) End If End If Else matDesc = Left(matDesc,idx24) & "<br/>" & Right(matDesc,LenMatDesc - idx24) End If Else matDesc = Left(matDesc,LenMatDesc - fSpace) End If Else If fSpace + sSpace < idx24 Then matDesc = Left(matDesc,LenMatDesc - (fSpace + sSpace)) Else matDesc = Left(matDesc,LenMatDesc - fSpace) End If End If Else If idx24 <> 0 Then matDesc = Left(matDesc,LenMatDesc - idx24) End If Else If idx24 <> 0 Then matDesc = Left(matDesc,LenMatDesc - idx24) End If Else '全部汉字 matDesc = Left(matDesc,12) & "<br/>" & Right(matDesc,LenMatDesc - 12) End If End If Return matDesc End Function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |