中英字符判断VB

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, fSpace) & "<br/>" & Right(matDesc, LenMatDesc - fSpace)
                                        End If
                                    End If
                                Else
                                    matDesc = Left(matDesc, idx24) & "<br/>" & Right(matDesc, LenMatDesc - idx24)
                                End If
                            Else
                                matDesc = Left(matDesc, fSpace) & "<br/>" & Right(matDesc, LenMatDesc - fSpace)
                            End If

                        Else
                            If fSpace + sSpace < idx24 Then
                                matDesc = Left(matDesc, fSpace + sSpace) & "<br/>" & Right(matDesc, LenMatDesc - (fSpace + sSpace))
                            Else
                                matDesc = Left(matDesc, fSpace) & "<br/>" & Right(matDesc, LenMatDesc - fSpace)
                            End If
                        End If
                    Else
                        If idx24 <> 0 Then matDesc = Left(matDesc, idx24) & "<br/>" & Right(matDesc, LenMatDesc - idx24)

                    End If
                Else
                    If idx24 <> 0 Then matDesc = Left(matDesc, idx24) & "<br/>" & Right(matDesc, LenMatDesc - idx24)
                End If
            Else
                '全部汉字
                matDesc = Left(matDesc, 12) & "<br/>" & Right(matDesc, LenMatDesc - 12)
            End If

        End If
        Return matDesc
    End Function

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值