如何使字符串查询第一行 [英] How Can I Make String To Query First Line

查看:82
本文介绍了如何使字符串查询第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        Dim showresult As String
        Dim txtlistname As String

        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            If CheckedListBox1.GetItemCheckState(i) = CheckState.Unchecked Then
                txtlistname += CheckedListBox1.Items(i).ToString() & Environment.NewLine
            End If
        Next

        MsgBox(txtlistname)

Msgbox: book.txt
        pen.txt
        ruler.txt

'how can i make the showresult display "book.txt" for the first query
'then second query display "pen.txt" and so..

   showresult = txtlistname 'book.txt'
   showresult = txtlistname 'pen.txt'
   showresult = txtlistname 'ruler.txt'

推荐答案

好吧,你的循环得到了每个未经检查的项目fr列表。



如果不是将它们连接成一个字符串,你可以将它们添加到一个集合中



(伪代码,因为我的VB生锈了)

在你所使用的方法之外创建一些集合(一个字符串数组就可以了)(如你所希望的那样)



执行您现有的方法,但将项目添加到集合中而不是(或同时)将它们连接成一个字符串)



现在你有一个字符串集合。



所以如果你想要遍历它们,你需要一些索引来显示你在哪里集合 - 以及返回项目并递增索引的方法。



您可以使用CheckedListBox作为您的集合 - 但如果用户随时进行交互,那么您当前的集合中的索引将无效(因为他们可能会检查或取消选中项目)



从您的问题ex中不是很清楚你要努力实现的目标,所以花时间更充分地描述你想要做的事情可能是值得的。
Well, you have your loop that gets each unchecked item from a list.

If instead of concatenating them into a string, you could add them to a collection

(pseudocode as my VB is rusty)
Create some collection (an array of strings would be fine) outside of the method you're in (as you want it to be retained)

Execute your existing method, but add the items to the collection instead of (or as well as) concatenating them into a string)

Now you have a collection of strings.

So if you want to iterate through them, you need some index to show you where you are in the collection - and a method that returns the item and increments the index.

You could just use the CheckedListBox as your collection - but if the user interacts at any time, then your current index into the collection will no linger be valid (as they may check or uncheck items)

It's not very clear from your question exactly what you are trying to achieve, so it may be worth spending the time to describe more fully what you are trying to do.


这篇关于如何使字符串查询第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆