如何阅读文本文件并替换多个关键字...... [英] How to Read a text file and replace multiple keywords...
问题描述
我正在尝试阅读包含一些独特关键字的文本文件,到目前为止我能够读取并替换1行的关键字,但我不知道如何阅读和替换文本文件中的所有关键字..?
我的文本文件如下所示,其中$ name,$ lastname& $ dob是要替换的关键字:
========================= ========
人名是:$ name
姓氏是:$ lastname
出生日期:$ dob
=================================
到目前为止,我的代码是:
I am trying to read a text file that contain some distinctive keywords, so far I am able to read and replace the keywords on 1 line, but I don't know how to read and replace all the keywords in the text file..?
My text file looks like this, where $name, $lastname & $dob are the keywords to be replaced:
=================================
The persons name is: $name
The lastname is: $lastname
Date of Birth: $dob
=================================
My code so far is:
Dim strFile As String = "c:\test.txt"
Dim strRead As StreamReader = File.OpenText(strFile)
Dim strX As String
Do Until strRead.Peek = -1
strX = strRead.ReadToEnd.Replace("$name", dt.Rows(0)("name"))
' strX = strRead.ReadToEnd.Replace("$lastname", dt.Rows(0)("lastname"))
tbConfig.Text = strX
Loop
推荐答案
name,
lastname&
lastname &
dob是要替换的关键字:
=========================== ======
人名是:
dob are the keywords to be replaced:
=================================
The persons name is:
这篇关于如何阅读文本文件并替换多个关键字......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!