Solved

string to acceptable filename

Posted on 1998-05-31
3
161 Views
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'
0
Comment
Question by:miauw
[X]
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
3 Comments
 
LVL 1

Accepted Solution

by:
Edo082297 earned 100 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);
begin
  Edit2.Text := RemoveInvalidFileCharacters(edit1.Text);
end;

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

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

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

Regards,

Edo

0
 

Author Comment

by:miauw
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.
0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1349477
Thanks, Miauw!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

726 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