问题
I have a text file contains delimited records.
1243;jhhf';982u4k;9u2349;huf8
kij;9238u;98ur23;jfwf;03i24
I need to replace the value of 4th part from every record with the value returned from database or someother source.
Any clue ? expecting VB CODE
回答1:
Take a look at here( for C# language ); Split string in C#
回答2:
You could try this (written in C#):
C# release
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 release
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())
来源:https://stackoverflow.com/questions/8922426/text-file-handling-in-visual-basic