Solved

Using 'in' for an Array, not a Set

Posted on 2004-04-05
4
168 Views
Last Modified: 2010-04-05
Is it possible to use the 'in' operator to find if an integer is in an array of integer?

The boolean-resulting:

7 in [5, 7, 9]

... would return TRUE for instance. Can I do something similar like:

7 in aNumbers

where aNumbers is an array of integer? Or do I have to do an ugly looping checker against each aNumbers[x] from 0 to length(aNumbers)?

Please give reasons for your answer: no points for just the quickest person to type "nope"   ;-)

Martin
0
Comment
Question by:MartinC
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10763370
defintivly no!

you need a function which loops through the array

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10763374
well, i need no points :-)))
0
 
LVL 11

Accepted Solution

by:
ZhaawZ earned 60 total points
ID: 10763444
If working with strings, it could be AnsiMatchText() (case insensitive) or AnsiMatchStr() (case sensitive) from StrUtils.
Looping through array is not so ugly:

function IntegerInArray (number : integer; const arr : array of integer) : boolean;
var n : integer;
begin
for n := low(arr) to high(arr) do if arr[n] = number then break;
result := n <= high(arr);
end;
0
 

Author Comment

by:MartinC
ID: 10763922
Ah well, if Kretzschmar The Infallible just says "nope" i guess I have to accept it ... thanks for promptness! Given that Kretschmar has said he doesn't need the points and Zhaawh has saved me even writing the function, and i am an incredibly lazy person, i'm gonna give the points to Zhaawh.

Thanks to both!

Martin
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 54
Newbie Thread Programming 1 118
find a node in VST 2 47
Delphi inherited method 6 42
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now