1,066
社区成员
发帖
与我相关
我的任务
分享
Dim a() As String, strLine As String
Open "xxx.csv" For Input As #1
Text1 = ""
Do Until EOF(1)
Line Input #1, strLine
a = Split(strLine, ",")
If Ubound(a) = 4 Then
a(3) = "" 'Remove PV2
strLine = Replace(Join(a, Space(1)), Space(2), Space(1))
Text1 = Text1 & strLine & vbcrLf
End If
Loop
Close #1
dim i as long
dim str as string, r as string
dim data() as string, lines() as string
open "xxx.csv" for input as #1
str = input(lof(1), 1)
close #1
lines = split(str, vbcrlf)
for i = lbound(lines) to ubound(lines)
data = split(lines(i), ",")
if i = lbound(lines) then
r = data(0) & " " & data(1) & " " & data(3) & " " & data(4)
else
r = r & vbcrlf & data(0) & " " & data(1) & " " & data(3) & " " & data(4)
end if
next
text1.text = r
这样可以快一点。dim i as long
dim str as string
dim data() as string, lines() as string
open "xxx.csv" for input as #1
str = input(lof(1), 1)
close #1
lines = split(str, vbcrlf)
for i = lbound(lines) to ubound(lines)
data = split(lines(i), ",")
if i = lbound(lines) then
text1.text = data(0) & " " & data(1) & " " & data(3) & " " & data(4)
else
text1.text = text1.text & vbcrlf & data(0) & " " & data(1) & " " & data(3) & " " & data(4)
end if
next
Dim strData As String
Dim reg As Object,match As Object
Open "xxx.csv" For Input As #1
strData = Input(LOF(1), 1)
Close #1
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.Pattern = "(.*?),(.*?),(.*?),(.*?),([^\r\n]*)"
Set matchs = reg.Execute(strData)
For Each match In matchs
Debug.Print match.SubMatches(0) & "," & match.SubMatches(1) & "," & match.SubMatches(3) & "," & match.SubMatches(4)
Next