
VB去重复行的问题,去除了需要的行?
代码如下:DimmyStr()AsString,myOutputAsString,iAsInteger,TxyStrAsString,TxtStr3AsStringOpe...
代码如下:
Dim myStr() As String, myOutput As String, i As Integer, TxyStr As String, TxtStr3 As String
Open App.Path & "\出库日志.txt" For Input As #1
n = 0
Do While Not EOF(1)
Line Input #1, tmp
If tmp <> "" And Trim(tmp) <> "" Then
TxtStr3 = TxtStr3 & vbCrLf & Trim(tmp)
End If
Loop
Close #1
myStr = Split(TxtStr3, vbCrLf)
For i = 0 To UBound(myStr)
If InStr(1, myOutput, myStr(i)) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
Next
Open App.Path & "\出库日志.txt" For Output As #1
Print #1, myOutput
Close #1
2011-10-26日销售中未出的批号有 1102182
2011-10-26日销售中未出的批号有 110218
如上它把第二行去掉了保留了第一行,但是它们不完全一样啊?如何修改让它以完全匹配去除 展开
Dim myStr() As String, myOutput As String, i As Integer, TxyStr As String, TxtStr3 As String
Open App.Path & "\出库日志.txt" For Input As #1
n = 0
Do While Not EOF(1)
Line Input #1, tmp
If tmp <> "" And Trim(tmp) <> "" Then
TxtStr3 = TxtStr3 & vbCrLf & Trim(tmp)
End If
Loop
Close #1
myStr = Split(TxtStr3, vbCrLf)
For i = 0 To UBound(myStr)
If InStr(1, myOutput, myStr(i)) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
Next
Open App.Path & "\出库日志.txt" For Output As #1
Print #1, myOutput
Close #1
2011-10-26日销售中未出的批号有 1102182
2011-10-26日销售中未出的批号有 110218
如上它把第二行去掉了保留了第一行,但是它们不完全一样啊?如何修改让它以完全匹配去除 展开
3个回答
展开全部
你对InStr的函数的功能没有完全理解
你的使用中参数1可以省
另外:
Instr("110218","1102182")的结果为0,其表示没有找到匹配
Instr("1102182","110218")的结果不为0,其表示找到匹配
instr的作用,在前面的字符串里找后面那个字符串
所以,需要修改代码:
myStr = Split(TxtStr3, vbCrLf)
既然你用到了数组,不妨这样做,将数组中相同内容的数据清空.
for i=0 to UBound(myStr)-1
for j=i+1 to UBound(myStr)
if trim(mystr(i)) = trim(mystr(j)) then
mystr(j)=""
end if
next j
next i
'然后,将非空的数组元素,加到文件里:
For i = 0 To UBound(myStr)
If ImyStr(i)) <>"" Then myOutput = myOutput & myStr(i) & vbCrLf
Next
Open App.Path & "\出库日志.txt" For Output As #1
Print #1, myOutput
Close #1
你的使用中参数1可以省
另外:
Instr("110218","1102182")的结果为0,其表示没有找到匹配
Instr("1102182","110218")的结果不为0,其表示找到匹配
instr的作用,在前面的字符串里找后面那个字符串
所以,需要修改代码:
myStr = Split(TxtStr3, vbCrLf)
既然你用到了数组,不妨这样做,将数组中相同内容的数据清空.
for i=0 to UBound(myStr)-1
for j=i+1 to UBound(myStr)
if trim(mystr(i)) = trim(mystr(j)) then
mystr(j)=""
end if
next j
next i
'然后,将非空的数组元素,加到文件里:
For i = 0 To UBound(myStr)
If ImyStr(i)) <>"" Then myOutput = myOutput & myStr(i) & vbCrLf
Next
Open App.Path & "\出库日志.txt" For Output As #1
Print #1, myOutput
Close #1
展开全部
这样改你试试
If InStr(1, myOutput, myStr(i)) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
改为
If InStr(1, myOutput, myStr(i) & vbCrLf) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
If InStr(1, myOutput, myStr(i)) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
改为
If InStr(1, myOutput, myStr(i) & vbCrLf) = 0 Then myOutput = myOutput & myStr(i) & vbCrLf
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不太懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询