Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

string to acceptable filename

Posted on 1998-05-31
3
Medium Priority
?
164 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 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);
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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

609 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