在|之前删除第一行分隔符?

时间:2014-04-14 22:17:09

标签: vb.net

我目前有一个大量的文字文件:

55964356-0a1f-4c8a-bafb-0f5a61e82e37|cselland|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.
217277ee-616b-43d7-8856-6019bc5be9a4|blazewing19|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.
e0187abe-b073-459b-a609-27104b16ceb5|shadowhunter2025|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.

我需要把它转换成这样的东西:

cselland|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.
blazewing19|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.
shadowhunter2025|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator.

我需要在|之前删除第一个块(随机字符串)在每一行,或者我可以从每一行删除前37个字符,但我不知道如何循环并执行此操作:/

Dim IReplace() = new String() {"|", (...)}

For Each word As String In IReplace
    value = value.Replace(word, Environment.NewLine & word)
Next

是我到目前为止所尝试的我不认为我走在正确的轨道上,任何人都可以帮我这个吗?

3 个答案:

答案 0 :(得分:0)

与几乎任何时候编辑具有非固定长度记录的文件一样,您必须读入文件并将其写回,就好像您正在写出一个全新的文件一样。唯一的好消息是,既然您要删除数据而不是添加数据,只要在输入和输出流上获得锁定权限,就可以使用相同的文件名。要帮助解析,请查看Microsoft.VisualBasic.TextFieldParser类型。

答案 1 :(得分:0)

我会使用IndexOf

获取您想要的每一行的一部分
Dim line as String = "55964356-0a1f-4c8a-bafb-0f5a61e82e37|cselland|2014-04-14 13:41:36 -0500|(Unknown)|Forever|Banned by an operator."
Dim indexofpipe as Integer = line.IndexOf('|')
Dim whatyouwant as String = line.Substring(indexofpipe+1) 'now whatyouwant is equal to the string after the pipe

答案 2 :(得分:0)

试试这个...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox2.Text = RemoveFirstChuckOfData(TextBox1.Text)
End Sub


Public Function RemoveFirstChuckOfData(ByVal Datas As String) As String

    RemoveFirstChuckOfData = Nothing

    Dim SeperateDatas() As String

    SeperateDatas = Datas.Split("|")

    For count = 1 To UBound(SeperateDatas)

        RemoveFirstChuckOfData &= SeperateDatas(count) & "|"

    Next

    RemoveFirstChuckOfData = RemoveFirstChuckOfData.Substring(0, RemoveFirstChuckOfData.Length - 1)

End Function

[55964356-0a1f-4c8a-bafb-0f5a61e82e37 | cselland | 2014-04-14 13:41:36 -0500 |(未知)|永远|被运营商禁止。] TO [cselland | 2014-04-14 13:41:36 -0500 |(未知)|永远|被运营商禁止。]删除第一个数据春天