Solved

string to acceptable filename

Posted on 1998-05-31
3
155 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now