vb.net - 从 CSV VB.net 中搜索数组的功能
问题描述
所以我做了一个函数的一部分,它读取 CSV 文件中的所有名称并将其输入到屏幕上,但现在我需要制作它,以便用户可以输入要搜索的名称,如果它在 CSV 文件中,那么它将告诉他们名字在文件中。这是我到目前为止所拥有的:
CSV 中的名称:
jack
tom
jeff
bill
bob
读取 csv 中的名称:
Dim location As String = "C:\Users\626284\Desktop"
Dim files As String = "names.csv"
Dim lines = File.ReadAllLines(Path.Combine(location, files))
System.Array.Sort(lines)
Console.WriteLine(String.Join(Environment.NewLine, lines))
搜索名称:Havent 解决了这部分问题。基本上程序不得不说
Console.WriteLine("Please enter a name you would like to search for")
search = Console.ReadLine()
If search = lines
then
Console.WriteLine("Name is found")
ElseIf
Console.WriteLine("Name isnt found")
解决方案
我会这样做:
Console.WriteLine("Please enter a name you would like to search for")
Dim search = Console.ReadLine()
If lines.Any(Function(line) line = search) Then
Console.WriteLine("Name is found")
ElseIf
Console.WriteLine("Name isnt found")
End If
推荐阅读
- java - 如何在导航抽屉中显示图像
- arrays - Julia 中的 Query.jl 可以从不同大小的数组创建行吗?
- laravel - Laravel:已经在查询集合后获取第一个项目?
- ios - Obj C - 一个接一个地呈现视图控制器
- python - 嗨,我需要有关制作 xpath 的帮助
- javascript - 如何让这个 Javascript 将我的背景更改为这个 URL?
- javascript - 如何在javascript中正确排序字符串数组
- excel - 如果函数过程中不满足条件,则退出 Sub
- css - :not() 中的两个类似乎在 Safari 中不起作用,但在 Firefox 和 Chrome 中起作用
- c++ - 我可以将 .clang-tidy 文件与 CMakeList.txt 一起使用吗?