gpt4 book ai didi

vb.net - 我的列表(字符串)被保存为 system.string (空)

转载 作者:行者123 更新时间:2023-12-03 09:25:40 28 4
gpt4 key购买 nike

我正在尝试删除选定的行,然后将其余行保存到文件中。但是,当我保存它时,它完全清空了文件。

    Console.Write("Please eneter the first name of the student you wish to search for: ")
searchfname = Console.ReadLine
searchfname = StrConv(searchfname, VbStrConv.ProperCase)
Console.Write("Please enter the second name of the student you wish to search for: ")
searchsname = Console.ReadLine
searchsname = StrConv(searchsname, VbStrConv.ProperCase)
Dim foundItem() As String = Nothing
Dim foundline As String = Nothing
Dim fnsearch As String = String.Join(searchfname, searchsname)
Dim lines As New List(Of String)(File.ReadAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls.csv"))
For Each line As String In lines
If searchfname = item(3) And searchsname = item(4) Then
Console.WriteLine(line)
Console.WriteLine()
Console.WriteLine("Are you sure you wish to delete this record? (y/n)")
End If
Dim answer As String
answer = Console.ReadLine
If answer = "y" Or answer = "Y" Then
Console.Clear()
lines.Remove(line)
Using sw As New StreamWriter("F:\Computing\Spelling Bee\stdnt&staffdtls.csv")
sw.WriteLine(lines.ToString)
End Using
ElseIf answer = "n" Or answer = "N" Then
staffmenu()
End If
Next

最佳答案

看看代码中的这一行:

sw.WriteLine(lines.ToString)

从该语句中提取 lines.ToString 表达式。该表达式的结果是“System.String”。您正在告诉流编写器将文本“System.String”写入文件。

要修复它,您需要类似这样的东西:

Using sw As New StreamWriter("F:\Computing\Spelling Bee\stdnt&staffdtls.csv")
For Each line As String In lines
sw.WriteLine(line)
Next line
End Using

关于vb.net - 我的列表(字符串)被保存为 system.string (空),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21835865/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com