Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 15797, Using case structure with strings

by William Egge Email: Anonymous


Using case structure for string lookup
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 2.0  to 5.0 1934 downloads
Copyright: No significant restrictions


Size: 357 bytes
Updated on Thu, 05 Apr 2001 14:34:01 GMT
Originally uploaded on Tue, 03 Apr 2001 14:21:57 GMT
SHA1 Hash: B01BFE6B8E33AF079C660FDC500FE4412E9EBFF4
MD5 Hash: A3E62274E3038A70855DF608E9C7B0AB

    Explore the files in this upload

Description
This is an easy function to write but it seems nobody thinks of it. The purpose is to be able to use a case structure with strings, in a way. You can download the unit from my website.
http://www.eggcentric.com/Fn_StringIndex.htm

Usage looks like this:
case StringIndex('Edit', ['Post', 'Edit', 'Cancel']) of
0: ; // Do somthing for Post "command"
1: ; // Do somthing for Edit "command"
2: ; // Do somthing for Cancel "command"
end;
.
.
.
or

if StringIndex('Edit', ['a', 'ab', 'rth']) = -1 then
// something
else
// something

I think thats self explanatory. Happy Coding!

Here I better just paste the unit directly in here:

unit Fn_StringIndex;

interface
uses
SysUtils;

function StringIndex(const SearchString: string; StrList: array of string): Integer;

implementation

function StringIndex(const SearchString: string; StrList: array of string): Integer;
var
I: Integer;
begin
Result:= -1;
for I:= 0 to High(StrList) do
if CompareText(SearchString, StrList[I]) = 0 then
begin
Result:= I;
Break;
end;
end;

end.

I also stuck this in the source code area because it seemed to apply there too.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03