读书人

VB 怎么清除无用的字符?如图

发布时间: 2012-01-08 22:48:50 作者: rapoo

VB 如何清除无用的字符?如图
就是清除掉文字间的符号数字,空格,字母,

如图

http://hiphotos.baidu.com/%CC%EC%B7%E7%BA%A3%CB%AE/pic/item/4493bb015c8564041d9583fe.jpg

[解决办法]
中文字的ASC值是负数 写个过程挨个判断就好了 是负数的复制到str变量中 再额外加个“,”不是就跳过
[解决办法]
text1是原文本框
text2是显示结果的文本框

Dim i As Integer
Dim tempStr As String
Text2.Text = " "
For i = 1 To Len(Text1.Text)
tempStr = Mid(Text1.Text, i, 1)
If Asc(tempStr) < 0 Then
Text2.Text = Text2.Text & tempStr & ", "
End If
Next i

运行结果:

源文本:Text1三地放松地放松dfsdf
结果文本:三,地,放,松,地,放,松,

加分!!!!
[解决办法]
Dim i As Integer
Dim tempStr As String
Text2.Text = " "
For i = 1 To Len(Text1.Text)
tempStr = Mid(Text1.Text, i, 1)
If Asc(tempStr) < 0 Then
Text2.Text = Text2.Text & tempStr & ", "
Else
If Asc(tempStr) = vbCrLf Then Text2.Text = Text2.Text & tempStr
End If
Next i

读书人网 >VB

热点推荐