VB 如何保留字符串中的中文英文数字
发布网友
发布时间:2023-07-02 20:46
我来回答
共3个回答
热心网友
时间:2024-07-24 00:02
可以考虑用ASC()遍历,首先要获得端点的ASC码(可以百度搜索0,9,A,z的ASC码及中文的ASC码范围,中文是负值,也可在立即窗口中键入?asc(*),*表示0,9,A,z),用mid函数获得逐字符,用asc函数返回其ASC码,大于0的ASC码小于9及大于大写A小于小写z(中文也同样)的字符不作修改,否则用null替代
楼上的做法在选出英文数字时可用,比我的方便,但中文的话要知道端点中文字符是什么去原则上是可以,但是比较烦。而且既然开头已经声明了不区分大小写,后面就没必要用UCASE转换大写,否则对非英文字符可能报错
热心网友
时间:2024-07-24 00:02
Option Explicit
Dim SS As String, SSnew As String
Private Sub Form_Load()
Dim I As Integer, J As Integer, St As String, St1 As String
SS = "dkow9843jqjoioio989&y*edNVN,KLFAJ; FJIOWI8*ii_{}“' D][A[FEWIU9U"
Form1.AutoRedraw = True
I = Len(SS)
For J = 1 To I
St = Mid(SS, J, 1)
St1 = UCase(St)
If St1 >= "A" And St1 <= "Z" Or St1 >= "0" And St1 <= "9" Then
SSnew = SSnew + St
End If
Next
Print SS
Print SSnew
End Sub
热心网友
时间:2024-07-24 00:03
a = "s大ss&&23"
temp = "abcdefghigklmnopqrstuvwxyz0123456789*"
l = Len(a)
If l >= 1 Then
For i = 1 To l
s = Mid(a, i, 1)
c = AscW(s)
If c < 0 Or c > 255 Then
Else
If InStr(temp, s) <= 0 Then
a = Replace(a, s, "*")
End If
End If
Next
End If
a = Replace(a, "*", "")
MsgBox a