vb求高手帮我写一段代码
DimsAsString,s1AsString,ZdnfZAsStringDimiAsInteger,jAsIntegerDimarr()AsString,ssAsStr...
Dim s As String, s1 As String, ZdnfZ As String
Dim i As Integer, j As Integer
Dim arr() As String, ss As String
Open Zdnf For Input As #1
Do While Not EOF(1)
Line Input #1, s
i = InStr(s, ",")
s1 = Mid(s, i + 1)
j = InStr(s1, ",")
If j <> 0 Then
s = Left(s, j + i - 1)
ZdnfZ = ZdnfZ + s + vbCrLf
Else
ZdnfZ = ZdnfZ + s + vbCrLf
End If
Loop
Close #1
Open Zdnf For Output As #1
arr = Split(ZdnfZ, vbCrLf)
For i = 0 To UBound(arr)
If Trim(Replace(arr(i), " ", "")) <> "" Then ss = ss & vbCrLf & arr(i)
Next
ZdnfZ = Mid(ss, 3)
Print #1, ZdnfZ
Close #1
这段代码是说删除每行第3个逗号后面的内容
求高手帮我写个 如果第三个逗号的内容是正常,则删除第4个逗号后面的内容
谢啦 展开
Dim i As Integer, j As Integer
Dim arr() As String, ss As String
Open Zdnf For Input As #1
Do While Not EOF(1)
Line Input #1, s
i = InStr(s, ",")
s1 = Mid(s, i + 1)
j = InStr(s1, ",")
If j <> 0 Then
s = Left(s, j + i - 1)
ZdnfZ = ZdnfZ + s + vbCrLf
Else
ZdnfZ = ZdnfZ + s + vbCrLf
End If
Loop
Close #1
Open Zdnf For Output As #1
arr = Split(ZdnfZ, vbCrLf)
For i = 0 To UBound(arr)
If Trim(Replace(arr(i), " ", "")) <> "" Then ss = ss & vbCrLf & arr(i)
Next
ZdnfZ = Mid(ss, 3)
Print #1, ZdnfZ
Close #1
这段代码是说删除每行第3个逗号后面的内容
求高手帮我写个 如果第三个逗号的内容是正常,则删除第4个逗号后面的内容
谢啦 展开
1个回答
展开全部
你这段代码好复杂啊,我给你改一下吧,主要改变
do while
loop
里面的东西就行,前面加两个变量定义
Dim s As String, s1 As String, ZdnfZ As String
Dim i As Integer, j As Integer
Dim arr() As String, ss As String
Dim m '这里加两个定义
Dim i_end As Integer
Open Zdnf For Input As #1
Do While Not EOF(1)
Line Input #1, s
'从这里开始
m = Split(s, ",")
If m(3) = "正常" Then
i_end = 4
'如果第三个逗号后面的文字是"正常",那么就去掉第四个逗号后面的内容
Else
i_end = 3
'否则,去掉第三个逗号后面的内容
End If
For i = 0 To i_end
s = s + "," + m(i)
Next i
ZdnfZ = ZdnfZ + s + vbCrLf
'原来的部分我给你注释掉了
' i = InStr(s, ",")
' s1 = Mid(s, i + 1)
' j = InStr(s1, ",")
' If j <> 0 Then
' s = Left(s, j + i - 1)
' ZdnfZ = ZdnfZ + s + vbCrLf
' Else
' ZdnfZ = ZdnfZ + s + vbCrLf
' End If
Loop
Close #1
Open Zdnf For Output As #1
arr = Split(ZdnfZ, vbCrLf)
For i = 0 To UBound(arr)
If Trim(Replace(arr(i), " ", "")) <> "" Then ss = ss & vbCrLf & arr(i)
Next
ZdnfZ = Mid(ss, 3)
Print #1, ZdnfZ
Close #1
你先试试,不行再说...
do while
loop
里面的东西就行,前面加两个变量定义
Dim s As String, s1 As String, ZdnfZ As String
Dim i As Integer, j As Integer
Dim arr() As String, ss As String
Dim m '这里加两个定义
Dim i_end As Integer
Open Zdnf For Input As #1
Do While Not EOF(1)
Line Input #1, s
'从这里开始
m = Split(s, ",")
If m(3) = "正常" Then
i_end = 4
'如果第三个逗号后面的文字是"正常",那么就去掉第四个逗号后面的内容
Else
i_end = 3
'否则,去掉第三个逗号后面的内容
End If
For i = 0 To i_end
s = s + "," + m(i)
Next i
ZdnfZ = ZdnfZ + s + vbCrLf
'原来的部分我给你注释掉了
' i = InStr(s, ",")
' s1 = Mid(s, i + 1)
' j = InStr(s1, ",")
' If j <> 0 Then
' s = Left(s, j + i - 1)
' ZdnfZ = ZdnfZ + s + vbCrLf
' Else
' ZdnfZ = ZdnfZ + s + vbCrLf
' End If
Loop
Close #1
Open Zdnf For Output As #1
arr = Split(ZdnfZ, vbCrLf)
For i = 0 To UBound(arr)
If Trim(Replace(arr(i), " ", "")) <> "" Then ss = ss & vbCrLf & arr(i)
Next
ZdnfZ = Mid(ss, 3)
Print #1, ZdnfZ
Close #1
你先试试,不行再说...
追问
留个QQ吧。。
追答
加我小号吧
1423169184
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询