string to acceptable filename

Posted on 1998-05-31
Medium Priority
Last Modified: 2010-04-06
I need a procedure RemoveInvalidFileCharacters(var Inputstring: string);
which substitutes invalid characters (that is for a Windows 95 filesystem)
by spaces.
e.g.   'TESTname' -> 'TESTname'
e.g.  'éééxamp^^^le' ->     '   xamp   le'
Question by:miauw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Edo082297 earned 400 total points
ID: 1349475
Hi Miauw,
  Here is your function. Note that Windows 95 will allow you to store filenames containing weird characters (other countries use these strange symbols; they even speak with them ;). You can also store filenames with special symbols like % and ^. You may not, however, use filenames that contain the following symbols: [\, /, :, *, ?, ", <, >, | ]. So, all we do is filter those out. If you want to block specific characters, you will have to add it to the filter list. Note that the function as it stands filters out some characters that are actually legal in a filename, but strange in the context of a filename (such as ^).

procedure TForm1.Button1Click(Sender: TObject);
  Edit2.Text := RemoveInvalidFileCharacters(edit1.Text);

function TForm1.RemoveInvalidFileCharacters(const AFileName : string): String;
  i : integer;
  Result := AFileName;

  // access violation will occurr in first iteration of for loop with blank string
  if Length(AFileName) = 0 then

  for i := 0 to Length(AFileName) do
    if not (AFileName[i] in ['0'..'z'])
        or (AFileName[i] in ['\', '/', ':', '*', '?', '"', '<', '>', '|']) then
      Result[i] := ' '




Author Comment

ID: 1349476
Thanks, I was ready by now, but you answered the question before I could
delete it, so I will give you A: Excellent.

Expert Comment

ID: 1349477
Thanks, Miauw!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 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