Text File Handling in Visual Basic

对着背影说爱祢 提交于 2019-12-13 09:22:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!