用line input循环读取文本后,怎么控制print输出(要改变其中某个字符串)??
以第一个字母为参考,原样保留字母第一次出现的那一行,剩下相同的字母变成+号
F,2427641,488389,52
F,2420099,501077,70
F,2416059,487970,62
F,2415877,496432,61
F,2415434,501170,48
O,2411708,496862,52
O,2408514,496789,49
O,2408367,503295,42
F,2404439,496544,33
F,2404350,502908,47
O,2396461,514017,41
O,2396464,522185,53
O,2392943,522507,61
T,2384907,513906,74
T,2384564,526574,21
T,2434500,522652,22
T,2434401,566821,24
H,2430901,530641,14
Y,2430363,552904,72
Y,2430316,551180,46
Y,2429235,556908,13
最终变成这样的
F,2427641,488389,52
+,2420099,501077,70
+,2416059,487970,62
+,2415877,496432,61
+,2415434,501170,48
O,2411708,496862,52
+,2408514,496789,49
+,2408367,503295,42
F,2404439,496544,33
+,2404350,502908,47
O,2396461,514017,41
+,2396464,522185,53
+,2392943,522507,61
T,2384907,513906,74
+,2384564,526574,21
+,2434500,522652,22
+,2434401,566821,24
H,2430901,530641,14
Y,2430363,552904,72
+,2430316,551180,46
+,2429235,556908,13
[解决办法]
open .... as #1
pre = ""
while not(eof(1))
s = lineinput
if pre <> left(s, 1) then
print s
else
print "+" + right(s, len(s - 1))
end if
pre = left(s, 1)
wend
[解决办法]
版主大人的流程,只有处理“相同的头字母是连续存放”的情况吧!
Private Sub Command1_Click()
Dim strLettBuf As String
Dim strTemp$, lFileSize&
Dim p1&, p2&
strLettBuf = ""
Open "X:\Temp\Test.txt" For Binary As #1
lFileSize = LOF(1)
Do
' 直接更改源文件!
p1 = Seek(1)
If (p1 >= lFileSize) Then Exit Do
Line Input #1, strTemp
If (Len(strTemp) > 0) Then
p2 = Seek(1)
If (InStr(strLettBuf, Left$(strTemp, 1)) > 0) Then
Put #1, p1, 43
Seek #1, p2
Else
strLettBuf = strLettBuf & Left$(strTemp, 1)
End If
End If
Loop
Close
End Sub