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