读取 listbox 的问题

hanbb1982 2005-10-20 12:10:49
下面是一个listbox 的列表
a.id
b.name
a.no
b.sex
a.name
b.age
b.id
a.addr
我们可以看到
listbox里面有相同的".id"和相同的".name"
我想得到的是它们"."的后门如果相同的话,我就拿一个就行了(比如:a.id,b,id这里我只需要输出一个a.id或者b.id)
然后把它写成:a.id,b.name,a.no,b.sex,b.age,a.addr
也就是把相同后缀名的去掉只留下一个就可以了.怎么样才能实现?

...全文
143 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
singlepine 2005-10-20
  • 打赏
  • 举报
回复
你的
a.id
b.name
a.no
b.sex
a.name
b.age
b.id
a.addr
是怎么帮上去的?只有知道它是怎么帮上去的,然后在绑定前才可以做判断把.后面重复的就不用榜上去,或者绑上以后,在用remove删掉也可以。

先要知道你是怎么绑定的,才好帮你解决。
fice_chen 2005-10-20
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arrLiB As New ArrayList
Dim i, j As Int16
For i = 0 To ListBox1.Items.Count - 1
arrLiB.Add(ListBox1.Items(i))
Next
For i = 0 To arrLiB.Count - 1
If i = arrLiB.Count Then Exit For
Dim strArr As String = arrLiB.Item(i)
Dim split() As String = strArr.Split(".")
Dim strHZ As String
For j = i + 1 To arrLiB.Count - 1
If j = arrLiB.Count Then Exit For
strHZ = arrLiB.Item(j)
strHZ = strHZ.Substring(strHZ.LastIndexOf(".") + 1)
If strHZ = split(1) Then
arrLiB.Remove(arrLiB.Item(j))
End If
Next
Next
ListBox1.Items.Clear()
For i = 0 To arrLiB.Count - 1
ListBox1.Items.Add(arrLiB.Item(i))
Next
End Sub
(个人意见,仅供参考)
ConanKid 2005-10-20
  • 打赏
  • 举报
回复
楼上正解
水如烟 2005-10-20
  • 打赏
  • 举报
回复
供参考:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tmp(Me.ListBox1.Items.Count - 1) As String
Me.ListBox1.Items.CopyTo(tmp, 0)
Console.WriteLine(GetSelectString(tmp))
End Sub

Private Function GetSelectString(ByVal Fields As String()) As String
If Fields.Length = 0 Then Return String.Empty
If Fields.Length = 1 Then Return Fields(0)

'复制这个数组
Dim tmpFields(Fields.Length - 1) As String
Fields.CopyTo(tmpFields, 0)

Dim n As Integer = tmpFields.Length - 1
Dim s As String

Do Until n = 0
s = tmpFields(n)
For i As Integer = n - 1 To 0 Step -1
If tmpFields(i).IndexOf(s.Substring(s.IndexOf("."c))) <> -1 Then
tmpFields(n) = String.Empty
Exit For
End If
Next
n -= 1
Loop

'去掉空值的新数组
n = 0
Dim tmp() As String
For Each s In tmpFields
If Not s.Equals(String.Empty) Then
ReDim Preserve tmp(n)
tmp(n) = s
n += 1
End If
Next

Return String.Join(",", tmp)
End Function
feiyun0112 2005-10-20
  • 打赏
  • 举报
回复
循环读listbox里面的数据
用arr=split(str,".")分成数组
然后存到hashtale,用.后面的字符串州关键字
ht(arr(1))=str
最后读出ht的值
hanbb1982 2005-10-20
  • 打赏
  • 举报
回复
不用理它怎么绑的,我要的是读这个listbox里面的数据

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧