4个回答
展开全部
Sub ReplaceTxt(TxtFilePath As String, ReplaceStr As String, Line As Integer) 'TxtFilePath表示txt文件路径,ReplaceStr表示用ReplaceStr覆盖原来的,Line表示覆盖第Line行
Dim i As Integer, FileNum As Integer
Dim TempStr As String, TxtLine() As String
FileNum = FreeFile
If Dir(TxtFilePath) = "" Then
Open TxtFilePath For Output As #FileNum
Close #FileNum
End If
Open TxtFilePath For Input As #FileNum
Do While Not EOF(1)
i = i + 1
ReDim Preserve TxtLine(1 To i) As String
Line Input #FileNum, TempStr
TxtLine(i) = TempStr
Loop
Close #FileNum
TxtLine(Line) = ReplaceStr
Open TxtFilePath For Output As #FileNum
For i = 1 To UBound(TxtLine)
Print #FileNum, TxtLine(i)
Next
Close #FileNum
End Sub
Private Sub Command1_Click()
Call ReplaceTxt("d:\2.txt", "this is a test", 16) '调用示例
End Sub
Dim i As Integer, FileNum As Integer
Dim TempStr As String, TxtLine() As String
FileNum = FreeFile
If Dir(TxtFilePath) = "" Then
Open TxtFilePath For Output As #FileNum
Close #FileNum
End If
Open TxtFilePath For Input As #FileNum
Do While Not EOF(1)
i = i + 1
ReDim Preserve TxtLine(1 To i) As String
Line Input #FileNum, TempStr
TxtLine(i) = TempStr
Loop
Close #FileNum
TxtLine(Line) = ReplaceStr
Open TxtFilePath For Output As #FileNum
For i = 1 To UBound(TxtLine)
Print #FileNum, TxtLine(i)
Next
Close #FileNum
End Sub
Private Sub Command1_Click()
Call ReplaceTxt("d:\2.txt", "this is a test", 16) '调用示例
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
iii = 16 '第几行
Dim arr() As Byte
Open "E:\1.txt" For Binary As #1
ReDim arr(1 To LOF(1))
Get #1, , arr
Close #1
arr1 = Split(StrConv(arr, vbUnicode), vbCrLf)
If iii - 1 < UBound(arr1) + 1 Then arr1(iii - 1) = Text1
Open "E:\2.txt" For Output As #1
Print #1, Join(arr1, vbCrLf)
Close #1
End Sub
iii = 16 '第几行
Dim arr() As Byte
Open "E:\1.txt" For Binary As #1
ReDim arr(1 To LOF(1))
Get #1, , arr
Close #1
arr1 = Split(StrConv(arr, vbUnicode), vbCrLf)
If iii - 1 < UBound(arr1) + 1 Then arr1(iii - 1) = Text1
Open "E:\2.txt" For Output As #1
Print #1, Join(arr1, vbCrLf)
Close #1
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-08-09
展开全部
如果你是软件配置之类的,建议用vb操作ini
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询