使用vb.net替换文本文件中的一行 [英] replace a line in a text file using vb.net

查看:87
本文介绍了使用vb.net替换文本文件中的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码替换一行

I am trying to replace a line using the following code

Dim reader As New StreamReader(strFile)
Dim line As String = reader.ReadLine
   While line <> ""

      line = reader.ReadLine
      If line <> "" Then
         Dim values() As String = line.Split(":")
          If values(0) = "GBPtoUSD" Then
             strFile.Replace(line, "GBPtoUSD:" + txtGBPtoUSD.Text)
          End If
 
      End If

    End While
reader.Close()



< br / >
我正在尝试使用

替换该行



I am trying to replace the line using

strFile.Replace(line, "GBPtoUSD:" + txtGBPtoUSD.Text)





但是它似乎不起作用。

请指教。



谢谢

Shailaja



but it doesnt seem to work.
Please advise.

Thanks
Shailaja

推荐答案

做一些事情:



1. ReadAllLines [ ^ ]进入arrya。

2.摆弄阵列,更换,移除等等。

3. WriteAllLines [ ^ ]到一个新文件。



点击文档中的链接查看示例。
Do somethign along the lines:

1. ReadAllLines[^] into an arrya.
2. Fiddle with the array, replace, remove etc.
3. WriteAllLines [^]to a new file.

Click on the links in the documentation to see the examples.


这篇关于使用vb.net替换文本文件中的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆