如何将变量分配给列表的所有元素(Of Strings) [英] How can I assign a variable to all elements of a list(Of Strings)
问题描述
我有一个项目需要一个完整的列表元素列表(Of String)。我不想将多个字符串转换为一个长字符串,而是某种变量(可能是一个Object?),当调用它时会插入一个列表的所有元素(Of String)。以下代码有效,但我不知道该列表将包含多少元素。
I have a project that needs a complete list of elements of a list(Of String). I don't want to convert multiple strings into one long string but rather some kind of variable (maybe it is an Object?) that when called will insert all elements of a list(Of String). The following code works but I don't know ahead of time how many elements the list will have.
Dim sailnums = New String() {var(0), var(1), var(2), var(3), var(4), var(5), var(6), var(7), var(8), var(9)}
Dim recog As New SpeechRecognitionEngine()
recog.SetInputToDefaultAudioDevice()
Dim nums As New Choices(sailnums)
Dim gram As Grammar = New Grammar(New GrammarBuilder(nums))
recog.LoadGrammar(gram)
RemoveHandler recog.SpeechRecognized, AddressOf recog_SpeechRecognized
AddHandler recog.SpeechRecognized, AddressOf recog_SpeechRecognized
recog.RecognizeAsync(RecognizeMode.Multiple)
什么我想做的是用大括号之间的字符串元素替换一个代表所有字符串元素的变量。
我该怎么做?
What I want to do is substitute the string elements in between the curly brackets with one variable that will represent all of the string elements.
How can I do this?
推荐答案
如果您使用List(of String)
,那么sailnums
可以从ToArray()
方法
所以如果var
是一个List(of String)
然后
If you use aList(of String)
thensailnums
can be assigned from theToArray()
method
So ifvar
is aList(of String)
then
Dim sailnums As String() = var.ToArray()
应该做你需要的事情
这篇关于如何将变量分配给列表的所有元素(Of Strings)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!