當前位置:編程學習大全網 - 編程軟體 - vb中怎麽批量替換特定的字符串?

vb中怎麽批量替換特定的字符串?

數據類型就是上面的樣子,也就是壹對壹對出現,中間用空格分開,每行都是這樣,就簡單。而且1234總是在前面。

假如數據結構不是這樣的話,方法也會變化的。

請明示 

張誌晨

Dim txtName As String

Function getFileName(dlg As Object) As String

'添加 commondialog1

'添加 file1, 可設為不可見 也就是只當作數組

On Error GoTo err

With dlg

.DialogTitle = "請指定文件夾"

.Filter = "文本文件(*.txt)|*.txt"

.ShowOpen

getFileName = .FileName

End With

Exit Function

err:

MsgBox "您沒有選擇文件或者文件夾中沒有txt文件"

End Function

'寫

Sub wirteTxt(namePath As String, txt As String)

Open namePath For Output As #1

Print #1, txt

Close #1

End Sub

'讀

Function lineRead(namePath As String) As String

'多行數據

Dim strLine As String

Dim strBox As String

Open namePath For Input As #1

Do Until EOF(1)

Line Input #1, strLine

strBox = strBox + strLine + vbCrLf

Loop

Text1(0).Text = strBox

Text1(1).Text = Replace(strBox, "1234", "5678")

Close #1

End Function

Private Sub Command1_Click()

txtName = getFileName(CommonDialog1)

lineRead txtName

End Sub

Private Sub File1_Click() '這只是修改壹個文件,妳可以用循環修改文件夾下所有的txt文件

lineRead File1.List(ListIndex)

wirteTxt txtName, Text1(1).Text

End Sub

  • 上一篇:C語言編程題,求結果和詳細過程。。。
  • 下一篇:Step7定時器編程方法
  • copyright 2024編程學習大全網