|
-
Oct 19th, 2012, 03:48 PM
#1
Thread Starter
New Member
Shortest string in a collection
Hi Forum,
I am trying to find the most efficient way to find the shortest string in a collection, and by shortest I mean the smallest index of. Any ideas on what would be the least resource intensive way to do this?
-
Oct 19th, 2012, 05:09 PM
#2
Re: Shortest string in a collection
Could you give an example? I was following up to where you defined shortest to mean something other than "the smallest number of characters", which is the typical definition of short when it comes to strings.
Also, which language are you talking about?
My usual boring signature: Nothing
 
-
Oct 21st, 2012, 08:10 PM
#3
Thread Starter
New Member
Re: Shortest string in a collection
Yeah, attached is a screenshot of my GUI, I am using MS Visual Studio, I am wanting to search through the listbox for the smallest (shortest) string and move it into the search result textb ox.
-
Oct 21st, 2012, 08:59 PM
#4
Re: Shortest string in a collection
Well we're all using Visual Studio, VB6 being a subset of VS 6 just as VB5 was part of VS97.
But it smells like some language and version of .Net based on the icon.
-
Oct 21st, 2012, 09:24 PM
#5
Re: Shortest string in a collection
So, the index of the shortest string?
There are ways to do it that use less code, but they are probably slower than the old fashioned way:
Code:
dim minIndex as integer
dim minLength as integer = Integer.Max
For x = 0 to listbox.Items.Count -1
if listbox.Items(x).Length < minLength Then
minLength = listbox.Items(x).Length
minindex=x
End If
Next
My usual boring signature: Nothing
 
-
Oct 21st, 2012, 09:41 PM
#6
Thread Starter
New Member
Re: Shortest string in a collection
Oh duh I am sorry, I am using VB 6, and thank you Shaggy Hiker, that seems to do it the quickest!
-
Oct 21st, 2012, 10:46 PM
#7
Re: Shortest string in a collection
 Originally Posted by uni_panther
Oh duh I am sorry, I am using VB 6, and thank you Shaggy Hiker, that seems to do it the quickest!
Are you really? If so then Shaggy's code is not going to work because it's written for VB.NET. That doesn't look like a VB6 icon on that form's title bar either. I think that you need to establish what you're actually using first. That's what the Help -> About menu item is for. Once we've established whether it's VB6 or, as I suspect, VB.NET then you can post to the correct forum in future, rather than General Developer where general development questions belong.
-
Oct 23rd, 2012, 09:15 AM
#8
Re: Shortest string in a collection
Yeah. If my code works, as written, then you aren't using VB6.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|