Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何读取列表框vb中每行的前2个数字。网_Vb.net_Visual Studio 2010 - Fatal编程技术网

Vb.net 如何读取列表框vb中每行的前2个数字。网

Vb.net 如何读取列表框vb中每行的前2个数字。网,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,我知道listbox有这样的行 12345678%32=5 4663578877fg 6883346899 等 我怎样才能得到每行的前两个数字是这样的 十二, 46 68 顺便说一句,列表框在每行的第一行中只有数字 谢谢 myListBox.Items.Add("1234") myListBox.Items.Add("567") myListBox.Items.Add("890") For position As Integer = 0 To myListBox.Items.Count - 1

我知道listbox有这样的行

12345678%32=5

4663578877fg

6883346899

我怎样才能得到每行的前两个数字是这样的

十二,

46

68

顺便说一句,列表框在每行的第一行中只有数字

谢谢

myListBox.Items.Add("1234")
myListBox.Items.Add("567")
myListBox.Items.Add("890")
For position As Integer = 0 To myListBox.Items.Count - 1
    myListBox.Items(position) = CStr(myListBox.Items(position)).Substring(0, 2)
Next
编辑

我们可以使用RichTextBox.Lines属性返回字符串数组。数组中的每个字符串表示RichTextBox中的一行。如果要在数组中存储前两位数字,可以尝试:

Dim intValues(Convert.ToInt32(RichTextBox1.Lines.Length)) As Integer 'Stores the digits
For position As Integer = 0 To Convert.ToInt32(RichTextBox1.Lines.Length) - 1
        intValues(position) = Convert.ToInt32(RichTextBox1.Lines(position).Substring(0, 2))
Next

你需要关于如何获取所有列表框或如何获取前两个字符的帮助吗?不是这个和这个,我想获取每行的前两个数字。。。。换句话说,我想删除所有行中的所有内容,除了每行中的前两个数字。。对不起,英语不好,你没听懂。。。我想获取列表框或richtextbox中每行的前2个数字。文本中有很多行file@ryan2014你没有提到richtextbox或文本文件。他提供的是你所要求的。像那样突然离开不会让你在这里有任何进展。如果这不是你想要的,我建议你用更好的细节来改变你的问题。同样根据你上面的评论“我想删除所有行中的所有内容,除了每行中的前两个数字……”他的建议答案是这样的。我没有。意思是,我试图解释更多,对不起,这是我的错。因为我用的是电话,所以我会用更多的信息来编辑这个问题details@ryan2014选中编辑以从RichTextbox获取值