Visual Basic中的文本文件处理 [英] Text File Handling in Visual Basic
本文介绍了Visual Basic中的文本文件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含分隔记录的文本文件.
I have a text file contains delimited records.
1243;jhhf';982u4k;9u2349;huf8
kij;9238u;98ur23;jfwf;03i24
我需要用数据库或其他来源返回的值替换每条记录的第4部分的值.
I need to replace the value of 4th part from every record with the value returned from database or someother source.
有任何线索吗?期待 VB代码
推荐答案
您可以尝试一下(用C#编写):
You could try this (written in C#):
C#版本
List<string> newLines = new List<string>();
string[] lines = File.ReadAllLines(filename);
foreach (string line in lines)
{
string[] parts = line.Split(";".ToCharArray());
parts[3] = string_from_db;
newLines.Add(String.Join(";", parts));
}
File.WriteAllLines(filename, newLines.ToArray());
VB.NET版本
Dim newLines As List(Of String) = New List(Of String)
Dim lines As String() = File.ReadAllLines(filename)
For Each line As String In lines
Dim parts As String() = line.Split(";")
parts(3) = string_from_db
newLines.Add(String.Join(";", parts))
Next
File.WriteAllLines(filename, newLines.ToArray())
这篇关于Visual Basic中的文本文件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文