Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search string for particular characters 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I know that I have seen something here that can do what I want, but I can't find the thread!!

I have a field in a query that is a citation number, if there are any of the following special characters in the citation number (@,#,%,&,*) then I want to set a boolean value, how can I look for any one of these characters in the string? I thought it was InStr, but I couldn't find anything on it.

Thanks!



Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
How to operate with Strings
faq102-3583

Regards




Steven van Els
SAvanEls@cq-link.sr
 
The easiest way to search for a set of characters in a string (assuming there are no pre-written functions) is:

For i := 1 to Length(String) do
begin
Case Ord(String) of
Ord('@') : Found := True;
//Add any others you need here
end;
end;

Not bad for being chucked together as I wrote this post.
 
Even easier (and I believe faster) would be
Code:
found := false;
for i := 1 to Length(citation) do begin
  if citation[i] in [ '@', '#', '%', '&', '*' ] then
    found := true;
end;
which actually meets Leslie's requirements.

Andrew


 
Thanks Andrew! That's perfect. I kinda thought InStr was VB, but I was hoping there was something similar.

Thanks for everyone's suggestions.

Leslie

Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
VB: Index = InStr("This is a nice day" ,"his")
Object Pascal: Index := Pos('his', 'This is a nice day');


Cheers
 
Then I guess I was mis-remembering what InStr does! Thanks richard!

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top