Hier noch die Fassung mit der zeichenspezifischen Umwandlung:
Delphi-Quellcode:
type
TCustomSign = packed record
Sign: Char;
TranslatedStr: string;
end;
const
CustomSigns: array[0..2] of TCustomSign =
(
(Sign: 'ö'; TranslatedStr: 'oe'), // <--- Hier die benutzerspezifischen Umwandlungen eintragen
(Sign: 'ü'; TranslatedStr: 'ue'),
(Sign: 'ä'; TranslatedStr: 'ae')
);
function GibMirNenWebsicherenDateinamenZurueck(const S: string): string;
function IsCustomSign(const aChr: Char; out TrnsltdStr: string): Boolean;
var
i: Integer;
begin
for i := Low(CustomSigns) to high(CustomSigns) do
if aChr = CustomSigns[i].Sign then
begin
Result := true;
TrnsltdStr := CustomSigns[i].TranslatedStr;
Exit;
end;
Result := false;
end;
var
aChr: Char;
insertIndex: Integer;
LastSignChanged: Boolean;
CustomStr: string;
begin
SetLength(Result, length(S));
insertIndex := 1;
LastSignChanged := false;
for aChr in S do
begin
if IsCustomSign(aChr, CustomStr) then
begin
LastSignChanged := false;
Insert(CustomStr, Result, insertIndex);
insertIndex := insertIndex + Length(CustomStr);
Continue;
end
else
if (aChr in ['a'..'z']) or
(aChr in ['0'..'9']) or
(aChr in ['A'..'Z']) then
begin
LastSignChanged := false;
Result[insertIndex] := LowerCase(aChr)[1]
end
else
if LastSignChanged then
Continue
else
begin
Result[insertIndex] := '_';
LastSignChanged := true
end;
inc(insertIndex);
end;
SetLength(Result, insertIndex-1);
end;
Wer eine saubere Fassung hat: Herzlichen Glühstrumpf