vb 去掉字符串
text1中有1432《》fckf99sdad……点击一个按钮在text2显示就是1432《》99……等于就是去掉中间的空格和字母...
text1中有 1432《》fc kf 99sdad …… 点击一个按钮
在text2显示就是1432《》99 ……
等于就是去掉中间的空格和字母 展开
在text2显示就是1432《》99 ……
等于就是去掉中间的空格和字母 展开
5个回答
展开全部
Dim str As String, str1 As String
str = Text1.Text
Dim i
For i = 1 To Len(str)
If Not (Mid(str, i, 1) = " " Or (Mid(str, i, 1) >= "A" And Mid(str, i, 1) <= "Z") Or (Mid(str, i, 1) >= "a" And Mid(str, i, 1) <= "z")) Then
str1 = str1 & Mid(str, i, 1)
End If
Next
Text2.Text= str1
str = Text1.Text
Dim i
For i = 1 To Len(str)
If Not (Mid(str, i, 1) = " " Or (Mid(str, i, 1) >= "A" And Mid(str, i, 1) <= "Z") Or (Mid(str, i, 1) >= "a" And Mid(str, i, 1) <= "z")) Then
str1 = str1 & Mid(str, i, 1)
End If
Next
Text2.Text= str1
展开全部
不晓得你的具体意思,你是只保留数字和特殊符号或是只保留数字和"《》"吗?
你又不打完整,只有照你的意思去做了
Private Sub Command1_Click()
Text2.Text = ""
Dim i
If Text1.Text <> "" Then
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) >= 48 And Mid(Text1.Text, i, 1) <= 57 Or Asc(Mid(Text1.Text, i, 1)) = -24138 Or Asc(Mid(Text1.Text, i, 1)) = -24137 Then
Text2.Text = Text2.Text & Mid(Text1.Text, i, 1)
End If
Next i
End If
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub
你又不打完整,只有照你的意思去做了
Private Sub Command1_Click()
Text2.Text = ""
Dim i
If Text1.Text <> "" Then
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) >= 48 And Mid(Text1.Text, i, 1) <= 57 Or Asc(Mid(Text1.Text, i, 1)) = -24138 Or Asc(Mid(Text1.Text, i, 1)) = -24137 Then
Text2.Text = Text2.Text & Mid(Text1.Text, i, 1)
End If
Next i
End If
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim i As Integer, t As String
Text2 = ""
For i = 1 To Len(Text1)
t = Mid(Text1, i, 1)
Select Case Asc(t)
Case 32: t = ""
Case Asc("a") To Asc("z"): t = ""
Case Asc("A") To Asc("Z"): t = ""
Case Else: Text2 = Text2 & t
End Select
Next
End Sub
Dim i As Integer, t As String
Text2 = ""
For i = 1 To Len(Text1)
t = Mid(Text1, i, 1)
Select Case Asc(t)
Case 32: t = ""
Case Asc("a") To Asc("z"): t = ""
Case Asc("A") To Asc("Z"): t = ""
Case Else: Text2 = Text2 & t
End Select
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
轮流判断 text1 中每个字符的asc码
32 空格
97-122 a-z
符合要求就往text2例添加
32 空格
97-122 a-z
符合要求就往text2例添加
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去掉中间的空格和字母:
Private Sub Command1_Click()
Text2 = GetStr(Text1)
End Sub
Function GetStr(ByVal s As String) As String
Dim i As Long
s = LCase(s)
s = Replace(s, Chr(32), vbNullString)
For i = 97 To 122
s = Replace(s, Chr(i), vbNullString)
Next
GetStr = s
End Function
Private Sub Command1_Click()
Text2 = GetStr(Text1)
End Sub
Function GetStr(ByVal s As String) As String
Dim i As Long
s = LCase(s)
s = Replace(s, Chr(32), vbNullString)
For i = 97 To 122
s = Replace(s, Chr(i), vbNullString)
Next
GetStr = s
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询