1

我想要做的是计算一个变量的字数。这是一个刽子手游戏,将用逗号分隔。所以我基本上希望变量看起来像这样:

"hang,man,group,toll,snail"

我打算用逗号分割它来创建一个数组,但除此之外,我完全不知道该怎么做。

另一方面,我很高兴看到任何其他关于整理要在刽子手游戏中使用的单词的建议!

4

5 回答 5

3

你已经成功了一半。

Dim wordCount as Integer = "hang,man,group,toll,snail".Split(",").Length

这会将其拆分为一个数组,然后返回该数组中的元素数。

于 2013-07-09T11:18:55.970 回答
2
Dim Words as String = "hang,man,group,toll,snail"

Dim Word = Words.Split(",")

所以结果将是.. Word(0) = "hang", Word(1) = "man" ... 以此类推..

于 2013-07-09T11:29:53.967 回答
1

像这样使用拆分

Dim words As String() = SOMESTRING.Split(New Char() {","c})

现在找到长度你可以

words.length ' set this to a variable or output

或者,您也可以单独使用这些词

words(0)     ' set this to a variable or output
words(1)     ' set this to a variable or output

等等

于 2013-07-25T18:22:48.760 回答
0

String.Split您可以使用该方法轻松地将字符串拆分为数组。

有许多重载,但我最常使用的是这个:

Dim myString as String = "hang,man,group,toll,snail"
Dim myStringArray as String()

myStringArray = myString.Split(new String { "," }, StringSplitOptions.None)

这将为您提供一个长度为 5 的字符串数组。

文档可以在这里找到:http: //msdn.microsoft.com/en-us/library/tabh47cf.aspx

于 2013-07-09T11:20:22.187 回答
0
Dim Text As String
Dim i As Integer
Dim ary() As String

Text =  "hang,man,group,toll,snail"
ary = Text.Split(",")

For i = 0 To UBound(ary)
    MsgBox(ary(i)) 'here you will get all the words in the array
Next i

MsgBox(i) 'You will get the number of items in your array
于 2013-07-09T11:48:26.670 回答