0

假设用户在文本框中输入了这样的字符串:

part1,part2,part3,part4.........partn

如何获取该字符串的部分总数

我尝试使用

dim part() as string = textbox1.text.split(",")

但我不知道如何获得零件总数

4

4 回答 4

2
 var count = textbox1.text.Split(",").Count();

或者

var count = textbox1.text.Split(",").Length;
于 2013-08-08T11:29:03.157 回答
2

完整的例子

string textbox1_text = "part1,part2,part3,part4";
int count = textbox1_text.Split(",").Count();
于 2013-08-08T12:15:04.960 回答
1

数组有一个Length属性:

Dim part() as string = textbox1.text.split(",")
Dim partCount as Integer = part.Length

如果您不需要零件数组,则可以只计算逗号:

Dim partCount as Integer = textbox1.text.Count(Function(c) c = ","c) + 1
于 2013-08-08T11:34:23.717 回答
0

不确定我是否正确理解了这个问题......但你可以使用

int count = textbox1.text.Split(",").Count();

在 C# 中

于 2013-08-08T11:28:20.177 回答