Quickly scan string if it contains certain characters

Posted on 2008-02-11
Medium Priority
Last Modified: 2012-06-22

I need to check if a string contains following characters/tokens (between the single qoutes).
'*','"','/','\','<','>','?',':','|'   (these are the characters/tokens that aren't allowed in filenames).

For entering individual characters in the editfield I use the function below in the OnKeyPress-event. But when a user paste a string into the editfield, this event isn't fired. Therefor I want to check the inserted string afterwards.

Can anybody supply me with a fast function that will do the trick? Or maybe a better solution is possible?
Regards, Stef
function GeldigTekenBestandsnaam(var Key : Char) : Boolean;
  Result := True;
  If (key in ['*','"','/','\','<','>','?',':','|']) then
    Result := False;

Open in new window

Question by:Stef Merlijn
  • 2
LVL 21

Accepted Solution

ziolko earned 2000 total points
ID: 20871102
const FORBIDEN = ['*','"','/','\','<','>','?',':','|'];
var s: string;
Result := True;
for cnt := 1 to Length(s) do
  if s[cnt] in FORBIDEN then begin
    Result := False;

LVL 21

Expert Comment

ID: 20871165
... make it a function and use in edit's OnChange event handler


Author Closing Comment

by:Stef Merlijn
ID: 31429991

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

601 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