中英字符判断VB

前端之家收集整理的这篇文章主要介绍了中英字符判断VB前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. Public Function FirstNoC(ByVal DescStr As String) As Dictionary(Of String,Integer)
  2. Dim fNoCIdx As Integer = 0
  3. Dim L = Len(DescStr$)
  4. Dim CNum As Integer = 0
  5. Dim fCnum As Integer = 0
  6. Dim idx24 As Integer = 0
  7. For n = 1 To L
  8. If Asc(Mid$(DescStr$,n,1)) < 0 Then
  9. fNoCIdx = 0
  10. If n + CNum >= 24 And n + CNum < 26 Then
  11. idx24 = n
  12. End If
  13. CNum += 1
  14. Else
  15. If fNoCIdx = 0 Then
  16. fNoCIdx = n
  17. fCnum = CNum
  18. End If
  19. End If
  20.  
  21. Next n
  22. Dim dic As New Dictionary(Of String,Integer)
  23. If idx24 > 0 Then
  24. idx24 -= 1
  25. End If
  26. If fNoCIdx > 0 Then
  27. fNoCIdx -= 1
  28. End If
  29. dic.Add("fullLen",L + CNum)
  30. dic.Add("fNoCIdx",fNoCIdx)
  31. dic.Add("CNum",CNum)
  32. dic.Add("fCnum",fCnum)
  33. dic.Add("idx24",idx24)
  34. FirstNoC = dic
  35. End Function

  1. Public Function GetMatDesc(ByVal matDesc As String)
  2. matDesc = matDesc.Replace(" "," ")
  3. '汉字后面第一个字符fNoCIdx,前面有多少汉字fCnum,转码后长度fullLen,汉字数量CNum,Dim dic As Dictionary(Of String,Integer) = FirstNoC(matDesc)
  4. '汉字后面第一个字符fNoCIdx
  5. Dim fNoCIdx As Integer = dic("fNoCIdx")
  6. '转码后总长度fullLen
  7. Dim fullLen As Integer = dic("fullLen")
  8. '汉字数量CNum
  9. Dim CNum As Integer = dic("CNum")
  10. '汉字后面第一个字符前汉字数量fCnum
  11. Dim fCnum As Integer = dic("fCnum")
  12. '20个字符中的汉字数
  13. Dim idx24 As Integer = dic("idx24")
  14. '总长度LenMatDesc
  15. Dim LenMatDesc As Integer = matDesc.Length
  16. '汉字后面第一个字符前总长度LenMatDesc
  17. Dim fClen As Integer = fCnum + fNoCIdx
  18.  
  19.  
  20. '---------------------------------------
  21. If fullLen = LenMatDesc Then
  22. '新增空格隔断
  23. Dim fSpace = matDesc.Split(" ")(0).Length
  24. Dim sSpace As Integer = 0
  25. If matDesc.Split(" ").Count > 1 Then
  26. sSpace = matDesc.Split(" ")(1).Length
  27. End If
  28.  
  29. If fSpace < 24 Then
  30. If fSpace + sSpace < 24 Then
  31. matDesc = Left(matDesc,fSpace + sSpace + 1) & "<br/>" & Right(matDesc,LenMatDesc - (fSpace + sSpace + 1))
  32. Else
  33. matDesc = Left(matDesc,fSpace) & "<br/>" & Right(matDesc,LenMatDesc - fSpace)
  34. End If
  35. Else
  36. matDesc = Left(matDesc,24) & "<br/>" & Right(matDesc,LenMatDesc - 24)
  37. End If
  38. Else
  39. '含有汉字
  40. If fullLen / 2 <> LenMatDesc Then
  41. '含有字符
  42. If fNoCIdx < 24 Then
  43. If fNoCIdx > 0 Then
  44. '新增空格隔断
  45. Dim fSpace = matDesc.Split(" ")(0).Length
  46. Dim sSpace As Integer = 0
  47. If matDesc.Split(" ").Count > 1 Then
  48. sSpace = matDesc.Split(" ")(1).Length
  49. End If
  50. If fSpace > fNoCIdx Then
  51. If idx24 <> 0 Then
  52. If fSpace < idx24 Then
  53. If fSpace + sSpace < idx24 Then
  54. matDesc = Left(matDesc,fSpace + sSpace) & "<br/>" & Right(matDesc,LenMatDesc - (fSpace + sSpace))
  55. Else
  56. If fSpace > idx24 Then
  57. matDesc = Left(matDesc,fNoCIdx) & "<br/>" & Right(matDesc,LenMatDesc - fNoCIdx)
  58. Else
  59. matDesc = Left(matDesc,LenMatDesc - fSpace)
  60. End If
  61. End If
  62. Else
  63. matDesc = Left(matDesc,idx24) & "<br/>" & Right(matDesc,LenMatDesc - idx24)
  64. End If
  65. Else
  66. matDesc = Left(matDesc,LenMatDesc - fSpace)
  67. End If
  68.  
  69. Else
  70. If fSpace + sSpace < idx24 Then
  71. matDesc = Left(matDesc,LenMatDesc - (fSpace + sSpace))
  72. Else
  73. matDesc = Left(matDesc,LenMatDesc - fSpace)
  74. End If
  75. End If
  76. Else
  77. If idx24 <> 0 Then matDesc = Left(matDesc,LenMatDesc - idx24)
  78.  
  79. End If
  80. Else
  81. If idx24 <> 0 Then matDesc = Left(matDesc,LenMatDesc - idx24)
  82. End If
  83. Else
  84. '全部汉字
  85. matDesc = Left(matDesc,12) & "<br/>" & Right(matDesc,LenMatDesc - 12)
  86. End If
  87.  
  88. End If
  89. Return matDesc
  90. End Function

猜你在找的VB相关文章