473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

search in a array

Jan
I've got the following array: FileIn(Counter)
How can i search the array for example "window"

TIA
Nov 21 '05 #1
8 3936
"Jan" <ca*****@planet.nl> schrieb:
I've got the following array: FileIn(Counter)
How can i search the array for example "window"

\\\
Dim FileIn() As String = ...
Array.Sort(FileIn)
Dim Index As Integer = Array.BinarySearch(FileIn, "window")
///

'BinarySearch' will only make sense for a sorted array. For unsorted
arrays, a linear search would be the "best" choice, but this would mean that
the item you are looking for is compared to all items in the list until the
item is found. This algorithm has a runtime of O(n) for n items and thus is
very slow for large arrays. Nevertheless, it's faster than sorting and then
using binary search. Binary search makes sense if you are searching several
times.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
"Jan" <ca*****@planet.nl> schrieb:
I've got the following array: FileIn(Counter)
How can i search the array for example "window"

\\\
Dim FileIn() As String = ...
Array.Sort(FileIn)
Dim Index As Integer = Array.BinarySearch(FileIn, "window")
///

'BinarySearch' will only make sense for a sorted array. For unsorted
arrays, a linear search would be the "best" choice, but this would mean that
the item you are looking for is compared to all items in the list until the
item is found. This algorithm has a runtime of O(n) for n items and thus is
very slow for large arrays. Nevertheless, it's faster than sorting and then
using binary search. Binary search makes sense if you are searching several
times.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
Jan,

There are in dotnet so many arrays, when it is created as this (a fixed
array )

dim FileIn(Counter) as String

Than it can be something as
\\\
dim i as integer
For i = 0 to FileIn.length
if FiliIn(i) = "window" then
exit for
Next
///
i is the place where it is, assuming you loaded it with a zero index as
starter.

I hope this helps?

Cor
Nov 21 '05 #4
Jan,

There are in dotnet so many arrays, when it is created as this (a fixed
array )

dim FileIn(Counter) as String

Than it can be something as
\\\
dim i as integer
For i = 0 to FileIn.length
if FiliIn(i) = "window" then
exit for
Next
///
i is the place where it is, assuming you loaded it with a zero index as
starter.

I hope this helps?

Cor
Nov 21 '05 #5
In addition to the other responses, you can use the IndexOf method of
the Array class, but it would not be suitable if your array had
duplicate entries:
MsgBox(Array.IndexOf(MyArrayVar,"window").ToString )

Chris

Nov 21 '05 #6
In addition to the other responses, you can use the IndexOf method of
the Array class, but it would not be suitable if your array had
duplicate entries:
MsgBox(Array.IndexOf(MyArrayVar,"window").ToString )

Chris

Nov 21 '05 #7
Chris,

The problem you tell, has my sample as well, so yours is in my opinion
better, I always skip that one you shows, I don't know why.

Cor
Nov 21 '05 #8
Chris,

The problem you tell, has my sample as well, so yours is in my opinion
better, I always skip that one you shows, I don't know why.

Cor
Nov 21 '05 #9

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

Similar topics

28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
1
by: cyrvb | last post by:
Hello, I'm a very very newbie in C# I did start 2 days ago, I get Visual Stuido 2005 C# I try to understand how to manage the arrays I did write this
10
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
5
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
36
by: lovecreatesbeauty | last post by:
Any comments are welcome for following the two sequential search C functions of both integer and string versions. Though they are simple, please do not laugh at it :) Could you give your great...
3
by: mdh_2972 | last post by:
I have an array of over 1000 links in a .JS file. I do not want to put the whole thing on my page because it would take to long to render the page. So how can I randomly pick 1 element from the...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
0
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.