本帖最后由 pcl_test 于 2015-7-14 20:34 编辑
回复 10# 328612167
本版规则
1、求助时,务必在顶楼一次性把问题交代清楚,建议给出完整有针对性的样本,样本过大可发网盘分享链接。勿发无意义的标题
2、使用 code 标记把代码部分括起来(选中代码后,单击回复框的 <> 按钮),以便复制。问题解决后,请编辑顶楼帖子在标题前面注明[已解决]- Dim fso,File1,File2,str,txt,arr,Dict
- Set Dict = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set File1 = fso.OpenTextFile(".\测试.txt", 1)
- Set File2 = fso.CreateTextFile(".\结果.txt", 2 ,False)
- n = 1000
- Do While File1.AtEndOfStream <> True
- str = File1.ReadLine
- txt = txt&str&vbCrLf
- If Left(str,10)="#328612167" Then def = 1
- arr = split(str,"|")
- If ubound(arr) > 6 Then
- If def=1 and Dict.Exists(arr(1)) <> True Then
- n=n+1
- Dict.Add arr(1), rtrim(arr(1))&"-A"&right(n,3)&" "
- End If
- End If
- Loop
-
- Dim tmp,objKeys,objItems
- objKeys = Dict.Keys
- objItems = Dict.Items
- For i = 0 To Dict.Count -1
- tmp = replace(txt,objKeys(i),objItems(i))
- txt = tmp
- Next
- File2.Write txt
- File1.Close
- File2.Close
- Dict.RemoveAll
- Set Dict = Nothing
- Msgbox "完成"
复制代码
|