A. VB过滤字符串【求助】
DimintLenAsInteger
DimiAsInteger
DimstrCurrentAsString
intLen=Len(Text1.Text)
Fori=1TointLen
strCurrent=Mid(Text1,i,1)
IfstrCurrent="."Or(Asc(strCurrent)>=48AndAsc(strCurrent)<=57)Then
Text2=Text2&strCurrent
EndIf
Next
B. vb中如何去掉字符串中的数字
从左到右一个一个字符判断,如果是数字忽略,如果不是数字,把字符放到一个新字符串中,最后得到的新字符串就是去掉数字后剩余的字符串。
C. VB数字的筛选
先放在数组里,再处理,数据一般都是在数组里进行处理的。
Private Sub Command1_Click()
Dim a1(100) As Integer
Dim a2() As Integer
Dim a3() As Integer
Text1 = ""
Text2 = ""
Text3 = ""
Randomize
For i = 0 To 100
a1(i) = Rnd * 100
Text1 = Text1 & a1(i) & " "
Next
j = 0
For i = 0 To 100
If a1(i) Mod 2 = 0 Then
ReDim Preserve a2(j)
a2(j) = a1(i)
Text2 = Text2 & a2(j) & " "
j = j + 1
End If
Next
j = 0
For i = 0 To UBound(a2)
If a2(i) > 50 Then
ReDim Preserve a3(j)
a3(j) = a2(i)
Text3 = Text3 & a3(j) & " "
j = j + 1
End If
Next
End Sub
D. vb字符串中提取数字
PrivateSubCommand1_Click()
DimsAsString,kAsInteger,c()AsString
DimpAsString,iAsInteger
s=Text1.Text
k=1
Fori=1ToLen(s)
IfMid(s,i,1)>="0"AndMid(s,i,1)<="9"Then
p=p&Mid(s,i,1)
ElseIfMid(s,i+1,1)>="0"AndMid(s,i+1,1)<="9"Andi<>1Then
Ifp<>""Then
ReDimPreservec(k)
c(k)=p
k=k+1
p=""
EndIf
EndIf
Nexti
ReDimPreservec(k)
c(k)=p
Fori=1Tok
List1.AddItem(c(i))
Nexti
EndSub
PrivateSubForm_Load()
Text1.Text=""
EndSub
E. 用VB来剔除一些数字
把以下代码存为Form1.frm即可,不需要再调试了
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3045
ClientLeft = 60
ClientTop = 450
ClientWidth = 4275
LinkTopic = "Form1"
ScaleHeight = 3045
ScaleWidth = 4275
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text2
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 375
Left = 2880
TabIndex = 3
Text = "0"
Top = 2280
Width = 855
End
Begin VB.CommandButton Command2
Caption = "小于"
Height = 375
Left = 1560
TabIndex = 2
Top = 2280
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "大于"
Height = 375
Left = 480
TabIndex = 1
Top = 2280
Width = 975
End
Begin VB.TextBox Text1
Height = 1575
Left = 480
MultiLine = -1 'True
TabIndex = 0
Top = 360
Width = 3255
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i, j, k
Dim num As Integer
Private Sub Command1_Click()
Text1.Text = ""
For i = 0 To 9
For j = i + 1 To 9
For k = j + 1 To 9
num = i + j + k
If num > Text2.Text Then '判断条件
Text1.Text = Text1.Text + CStr(i) + CStr(j) + CStr(k) + " "
End If
Next k
Next j
Next i
End Sub
Private Sub Command2_Click()
Text1.Text = ""
For i = 0 To 9
For j = i + 1 To 9
For k = j + 1 To 9
num = i + j + k
If num < Text2.Text Then '判断条件
Text1.Text = Text1.Text + CStr(i) + CStr(j) + CStr(k) + " "
End If
Next k
Next j
Next i
End Sub
F. vb如何对一段数字做筛选
Private Sub Command1_Click()
Dim s() As String
s = Split(Text1, " ")
Text2 = ""
For i = 0 To UBound(s)
If IsNumeric(s(i)) And Len(s(i)) = 11 And Left(s(i), 3) = "123" Then
Text2 = Text2 & s(i)
End If
Next
End Sub
G. vb怎样过滤掉重复的数字和不是数字的内容,并保留其中百分之十
arr = fc(arr, mark)
下面插入一行
ReDim Preserve arr(UBound(arr) * 0.3)
H. vb过滤掉其中出现过的一些数字
Private Sub Command1_Click()
'导入到来源text1
Open App.Path & "\3d.txt" For Input As #1
Do While EOF(1) = False
Line Input #1, a
Text1 = Text1 & a & vbCrLf
Loop
Close
End Sub
Private Sub Command2_Click()
'导入到文件
Open App.Path & "\334.txt" For Output As #2
Print #2, Text2.Text
Close
End Sub
Private Sub Command3_Click()
'过滤数字
Dim T2 As String
For I = 1 To 100
If InStr(Text1, I & vbCrLf) = 0 Then
If T2 = "" Then T2 = I Else T2 = T2 & vbCrLf & I
End If
Next I
Text2 = T2
End Sub
I. 用vb怎样过滤掉文本中重复的数字和不是数字的内容
Option Explicit
Private Sub Command1_Click()
Dim arr, mark, dic, i
mark = ""
arr = "下:京(6699) 上海(4789) 美国(87968)……(6699)……当然并不(123)都是怎(456)样把"
arr = fc(arr, mark)
Set dic = CreateObject("scripting.dictionary")
For i = LBound(arr) To UBound(arr)
If Not dic.Exists(arr(i)) Then dic.Add arr(i), ""
Next
arr = dic.keys
Print Join(arr)
Open "c:\a.txt" For Output As #1
Print #1, Join(arr)
Close #1
Set dic = Nothing
End Sub
Function fc(s, mark)
Dim arr, brr(), i, n, str
If InStr(s, "(") > 0 Then
arr = Split(s, "(")
For i = 0 To UBound(arr)
If InStr(arr(i), ")") > 0 Then
str = Split(arr(i), ")")(0)
If IsNumeric(str) Then
ReDim Preserve brr(n)
brr(n) = Split(arr(i), ")")(0) & mark
n = n + 1
End If
End If
Next
End If
fc = brr
End Function
J. vb中,有12这个数字,要想把以下TEXT中的内容过滤掉:123,012,102,234,987,103,182
若分别用text1(0),text1(1),text1(2)......text1(n)存放一个数字,可用以下条件判断
for i=0 to n
if isstr(text1(i).text,"1")>0 and isstr(text1(i).text,"2")>0 then text1(i).text="" '同时含有回答1、2字符
next
或
for i=0 to n
if isstr(text1(i).text,"1")>0 or isstr(text1(i).text,"2")>0 then text1(i).text="" '含有1、2字符的其中一个
next
if isstr(text(i).text,"1")>0 and isstr(text(i).text,"2")>0 then