Fórum Ajudinha em uma funcao #239520
24/06/2004
0
estou com uma duvida...
tenho a seguinte string ´antônio de souza´ queria que uma funcao retornasse a primeira letra
dos nomes em maiusculo, tirando o DE, E, DA e etc...
fiz a seguinte funcao, ela me retorna todos os nomes em maiusculo, nao consegui fazer o DE, E e DA etc.. ficar em minusculo...
function FormataTexto(const Texto: string): string; var i, ant: integer; s: string; begin for i := 0 to Length(Texto) do begin if Texto[i] = ´ ´ then begin ant := i; s := s + Texto[i]; end else begin if i = (ant + 1) then begin s := s + UpperCase(Texto[i]); end else s := s + Texto[i]; end; end; Result := s; end;
Como arrumo isso?
Desde ja agradeco,
Fellipe
Titanius
Curtir tópico
+ 0Posts
24/06/2004
Rs_ferreira
Gostei + 0
24/06/2004
Marcelo Saviski
function FormataTexto(const Texto: string): string; var i, ant: integer; s: string; s2: string[2]; s3: string[3]; begin i := 0; while i <= Length(Texto) do begin if Texto[i] = ´ ´ then begin ant := i; s := s + Texto[i]; end else begin s2 := AnsiLowerCase(Copy(Texto, i, 2)); s3 := AnsiLowerCase(Copy(Texto, i, 3)); if (s2 = ´de´) or (s2 = ´da´) or (s2 = ´do´) then begin s := s + s2; Inc(i, 2); end; if (s3 = ´das´) or (s3 = ´dos´) or (s3 = ´ e ´) then begin s := s + s3; Inc(i, 3); end; end begin if i = (ant + 1) then begin s := s + UpperCase(Texto[i]); end else s := s + Texto[i]; end; Inc(i); end; Result := s; end;
Gostei + 0
25/06/2004
Emerson Nascimento
function TForm1.FormataTexto(Texto: string): string;
const
    Excessao: array[0..5] of string = (´ de ´,´ do ´,´ da ´,´ dos ´,´ das ´,´ e ´);
var
    i: integer;
begin
    Result := Texto;
    if Texto = EmptyStr then
        exit;
    Result[1] := AnsiUpperCase(Result[1])[1];
    for i := 2 to Length(Result) do
        if Result[i-1] = ´ ´ then
            Result[i] := AnsiUpperCase(Result[i])[1]
        else
            Result[i] := AnsiLowerCase(Result[i])[1];
    for i := 0 to High(Excessao) do
        Result := StringReplace( Result,Excessao[i],Excessao[i],[rfReplaceAll,rfIgnoreCase] );
end;
altere a constante Excessao da forma que lhe for mas adequada.
espero que seja útil.
Gostei + 0
25/06/2004
Titanius
[]s
Fellipe :D
Gostei + 0
25/06/2004
Cleisonsilva2004
VC PODE UTILIZAR A FUNÇÃO ReplarceStr em contradas
nas dicas dtdelphi
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)