VB 文本指定行字符串的替代

2025-12-05 21:44:18
推荐回答(1个)
回答1:

'用VBS写的,做个参考吧!

dim m(3,3) '要根据内容所定
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("1.txt")
while file.atendofstream<>true
h=h+1
n=file.readline:s=split(n):l=ubound(s)
for i=0 to l
m(h,i+1)=s(i)
next
wend
file.close

m(2,2)="12":m(3,1)="10" '可以根据你想替换的内容进行修改

for i=1 to 3
for j=1 to 3
if j=3 then
sm=sm & m(i,j) & vbcrlf
else
sm=sm & m(i,j) & " "
end if
next
next

set file=fso.opentextfile("1.txt",2)
file.write sm
file.close

createobject("wscript.shell").run "notepad.exe 1.txt"