查找并替换文本文件中的文本

时间:2014-04-14 18:21:21

标签: vb.net replace

我正在创建一个程序,用于在单词路径中查找特定句子并将其替换为给定值。

特定句子:l="600"

必须更改为:l="300"

这并不困难并且工作正常:

Public Class Form1

Private Property sign As String

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim sign1 As String
Dim sign2 As String


sign1 = ("""600""") 'original value
sign2 = ("""300""") 'New value

Dim source As String = "C:\temp\bodem.mpr" 'path from original file
Dim destination As String = "C:\temp\bodem2.mpr" 'path new file
Dim oldText As String = "l=" & sign1 'old value
Dim newText As String = "l=" & sign2 'new value

My.Computer.FileSystem.WriteAllText(destination, My.Computer.FileSystem.ReadAllText (source).Replace(oldText, newText), False)
Process.Start("C:\temp\bodem2.mpr") 'opens program in wordpath to control value
End Sub 

End Class

唯一的问题是原始句子:l="600"并不总是具有值600,而是始终具有我不知道的不同值。 (例如:l =" 600" / l =" 600.02" / l =" 300" / l =" 1600.02")如何我可以在我的代码中写下来吗。

0 个答案:

没有答案