assume in a text box a user input a string like this:
在文本框中假设用户输入如下字符串:
part1,part2,part3,part4.........partn
how to get the total number of parts of that string
如何获取该字符串的部分总数
I tried using
我试过用
dim part() as string = textbox1.text.split(",")
but I do not know how to get the total number of parts
但我不知道如何获得零件总数
4 个解决方案
#1
2
var count = textbox1.text.Split(",").Count();
OR
要么
var count = textbox1.text.Split(",").Length;
#2
1
The array has a Length
property:
该数组具有Length属性:
Dim part() as string = textbox1.text.split(",")
Dim partCount as Integer = part.Length
If you don't need the array of parts, you can just count the commas:
如果您不需要部件数组,则可以只计算逗号:
Dim partCount as Integer = textbox1.text.Count(Function(c) c = ","c) + 1
#3
0
Not sure if I understand the problem correctly...but you could just use
不确定我是否正确理解了问题...但你可以使用
int count = textbox1.text.Split(",").Count();
in C#
在C#中
#4
0
full example
完整的例子
string textbox1_text = "part1,part2,part3,part4";
int count = textbox1_text.Split(",").Count();
#1
2
var count = textbox1.text.Split(",").Count();
OR
要么
var count = textbox1.text.Split(",").Length;
#2
1
The array has a Length
property:
该数组具有Length属性:
Dim part() as string = textbox1.text.split(",")
Dim partCount as Integer = part.Length
If you don't need the array of parts, you can just count the commas:
如果您不需要部件数组,则可以只计算逗号:
Dim partCount as Integer = textbox1.text.Count(Function(c) c = ","c) + 1
#3
0
Not sure if I understand the problem correctly...but you could just use
不确定我是否正确理解了问题...但你可以使用
int count = textbox1.text.Split(",").Count();
in C#
在C#中
#4
0
full example
完整的例子
string textbox1_text = "part1,part2,part3,part4";
int count = textbox1_text.Split(",").Count();