从列表中获取特定值
问题描述:
您好,
我需要从外部文本文件中读取列表中的第一个值。
I need to get the first value out of a list I'm reading from an external text file.
文件显示如下:
好的,魔术帮派
等...
我需要只需读取逗号前的值。
I need to just read the value before the comma.
任何帮助都将不胜感激。
Any help would be appreciated.
答
嗨
这是一种方法:
' file may have multiplr lines
' read all lines from it
Dim allitems As List(Of String) = IO.File.ReadLines(path).ToList
' take first line and split at ","
Dim items As String() = allitems(0).Split(","c)
' put desired item into variable
Dim wanteditem As String = items(0)