Substituir caracteres especiais em Strings Delphi
Today I had to modify an ancient system done in Delphi to generate files containing some information. Nestas informações há elementos que se utilizam de caracteres não Alpha-numéricos como “;:”; e “;/”; and behold, to my surprise I am obligated to remove them.
Procurei por uma função que substituísse caracteres como “;Ç”; para “;C”; and only found removal functions.
Then I created my that is just below.
{
Replaces special characters for ASCII equivalents
}
Function ReplaceNonAscii(const s: String) : String;
var i, POS: Integer;
const undesiredchars : String = '/ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÜÚÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ';
const replaces : String = ' AAAAAAACEEEEIIIIDNOOOOOxOUUUbBaaaaaaaceeeeiiiionooooo ouuuby';
Begin SetLength(Result, Length(s));
for i := 1 to Length(s) Do start then := ord(s[i]);
if (s[i] in [#32, #48..#57, #65..#90, #97..#122]) then Result[i] := s[i]
else begin pos := AnsiPos(s[i], undesiredchars);
Result[i] := replaces[POS + 1];
end;
end;
end;

2 Responses
Could put it right? and untranslated
It's even better to understand, do que tentar decifrar o que é “;para eu”; e “;final”;
Não entendi o questionamento.