473,608 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Array.Bi narySearch

Okay, I can certinatly use a For..Next loop to find the specified info I
need, but I'm thinking the BinarySearch will be faster, if I can get it
working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the
string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)

Frustraiting,
Sueffel

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
Nov 20 '05 #1
8 3032
"Sueffel" <so*****@somewh ere.com> schrieb
Okay, I can certinatly use a For..Next loop to find the specified
info I need, but I'm thinking the BinarySearch will be faster, if I
can get it working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to
find the string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)


Where is the problem? Read the description of the return value in the docs
for BinarySearch.
--
Armin

Nov 20 '05 #2
Are you sure your array is sorted?
"Sueffel" <so*****@somewh ere.com> wrote in message
news:OX******** ******@TK2MSFTN GP09.phx.gbl...
Okay, I can certinatly use a For..Next loop to find the specified info I
need, but I'm thinking the BinarySearch will be faster, if I can get it
working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the
string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)

Frustraiting,
Sueffel

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004

Nov 20 '05 #3
Cor
Hi Sueffel,

Are you an old Cobol programmer who had to do with the magic of the binary
search in that.

Why should a binary Search be faster.

Did you already look at the array.indexof method?

Cor

Okay, I can certinatly use a For..Next loop to find the specified info I
need, but I'm thinking the BinarySearch will be faster, if I can get it
working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the
string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)

Nov 20 '05 #4
To resond to Armin first:

My array length is 1236, the BinarySearch is returning -1231, and in this
case I know that the string I'm looking for is at element 11, so there's no
correlation. I have followed the example to the letter, and this is waht I
get. I'm getting frustraited with this...

And now to William:

Here's my Code, verbatum:

'Air Code'
System.Array.So rt(FST) 'FST is my array with 1236 Elements in it
Dim MySearchObj As Object = "MD5 message digest"
I= System.Array.Bi narySearch(FST, MySrchObj)
MsgBox(I)
'*******'

The only thting I can figure, is the string in the file is:
"MD5 message digest filename
"

problem is, .NET is trimming the end, so, I need to do a search only using
part of the string. I can do this very easily with a For...Next loop, but
with 5,000 elements, we can see that this is probably not the most efficient
way of doing this.

Thanks again,
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
Nov 20 '05 #5
* "Sueffel" <so*****@somewh ere.com> scripsit:
Okay, I can certinatly use a For..Next loop to find the specified info I
need, but I'm thinking the BinarySearch will be faster, if I can get it
working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the
string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)


<msdn>
Return Value

The index of the specified value in the specified array, if value is
found.

-or-

A negative number, which is the bitwise complement of the index of the
first element that is larger than value, if value is not found and value
is less than one or more elements in array.

-or-

A negative number, which is the bitwise complement of (the index of the
last element + 1), if value is not found and value is greater than any
of the elements in array.
</msdn>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

"Cor" <no*@non.com> wrote in message
news:eQ******** ******@TK2MSFTN GP09.phx.gbl...
Hi Sueffel,

Are you an old Cobol programmer who had to do with the magic of the binary
search in that.

Why should a binary Search be faster.

Did you already look at the array.indexof method?

Cor

Okay, I can certinatly use a For..Next loop to find the specified info I
need, but I'm thinking the BinarySearch will be faster, if I can get it
working LOL

Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the string, say it's "Start here".

I've tried this:
Dim MyObj as Object = "Start Here"
Dim I as Integer = System.Array.Bi narySearch(MyAr r,MyObj)

and I get stuff like -1267 (Or size of array)



No, no cobol programmer, but, binary is faster than string or hex searching.
nature of computing. I'm going to look at indexOf though, that may be my
answer.

Thanks again everyone,
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
Nov 20 '05 #7
Sueffel,
You do realize that BinarySearch does an exact match:
Dim MySearchObj As Object = "MD5 message digest"
Does element 11 have "MD5 message digest" exactly, if it does its index
should be returned.

Or does it have "MD5 message digest
filename", in which case it does not match, and you get the negative number.

As both the extra spaces and filename will not allow it to match!

In your For Next, I take it you are using String.StartsWi th to get an
approximate match?

Hope this helps
Jay

"Sueffel" <so*****@somewh ere.com> wrote in message
news:OY******** ******@TK2MSFTN GP12.phx.gbl... To resond to Armin first:

My array length is 1236, the BinarySearch is returning -1231, and in this
case I know that the string I'm looking for is at element 11, so there's no correlation. I have followed the example to the letter, and this is waht I get. I'm getting frustraited with this...

And now to William:

Here's my Code, verbatum:

'Air Code'
System.Array.So rt(FST) 'FST is my array with 1236 Elements in it
Dim MySearchObj As Object = "MD5 message digest"
I= System.Array.Bi narySearch(FST, MySrchObj)
MsgBox(I)
'*******'

The only thting I can figure, is the string in the file is:
"MD5 message digest filename
"

problem is, .NET is trimming the end, so, I need to do a search only using
part of the string. I can do this very easily with a For...Next loop, but
with 5,000 elements, we can see that this is probably not the most efficient way of doing this.

Thanks again,
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004

Nov 20 '05 #8
Indexof works like a wet dream!

Thanks again everyone,
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 2/20/2004
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12039
by: Abraham Lopez | last post by:
Hi.. Is there a way to convert a System.Array to XML... If you know thanks very much... if you don't... Please do not respond stupid things like " Yes -- many ways."
2
2732
by: Chris | last post by:
Hi, the specs for System.Array are : MustInherit Public Class Array Implements ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code Dim numbers As System.Array
2
1497
by: Yogi21 | last post by:
Hi I have a sorted array containing strings. I am iterating through the array and clearing the contents one by one using "array.BinarySearch" to find each element. So far so good. But the moment I come to the last element, the BinarySearch method fails.It gives me a return value which is negative although the element is very much there. I am debugging through the code and I find nothing wrong with it.Note that i am using the first overloaded...
2
3937
by: Mario | last post by:
Hi there, I'm writing a piece of code with VS.Net 2003, Framework 1.1. And I can't make BinarySearch to work right. Look at this sample: Dim sexy() As String = {"-", "a", "b", "ba", "A", "Aa", "Ab", _ "Aba", "B", "Ba", "Bb", "Bba", "BA", "BAa", "BAb", "BAba"} Dim index As Integer
1
3762
by: m830266 | last post by:
I'm trying to use the APAX serial I/O control (www.turbocontrol.com/AProZilla.htm) in a VB.NET project and I'm having trouble with its 'data received' events. The data is supplied by APAX as a variant which appears to VB.NET as a System.Object. I want to convert this to a System.Array so that I can iterate over its elements. The VB6 usage is described at www.turbocontrol.com/TechTips/20020426.htm. If I try something similar in...
5
19577
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
3
5453
by: clawton | last post by:
Hi All - I've got a 3rd party COM object that returns an array of bytes that are a TIFF image. After adding the reference to the com object to my solution the C# signature for the method is something like this: System.Array Item.GetContent(); I need to save the bytes to a file that will be the tiff file...so when I
0
904
by: esoj | last post by:
using System.Text; using System; namespace beta { class core {
2
6139
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists, like List<char>. What I have working is : Type type = newObj.GetType(); //newObj is what I'm trying to dump
0
8069
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8503
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6826
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3972
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1339
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.