Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Cómo quitar espacios inicial y final en cadena (https://www.clubdelphi.com/foros/showthread.php?t=85478)

bulc 22-03-2014 18:24:33

Cómo quitar espacios inicial y final en cadena
 
Tengo este ejercicio y no puedo quitar los espacios inicial y final de una cadena. ¿Qué se puede hacer?
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
Var
  sTrim, sMay, sMin, sDigit : String;
  nLongi, wNum, nResto, nMay, nMin, nDigit: Word;
begin
 wNum:=0; nMay:=0; nMin:=0; nDigit:=0; nResto:=0;
 sMay:=''; sMin:=''; sDigit:= '';

 sTrim:=TRIM(Memo1.Text);
 nLongi:=Length(sTrim);
 for wNum := 1 to Length(sTrim) do
 case Memo1.Text[wNum] of
 '0'..'9': nDigit := nDigit +1;
 'A'..'Z','Ñ', 'Á','É', 'Í', 'Ó','Ú','Ü': nMay:= nMay+1;
 'a'..'z','ñ','á','é','í','ó','ú','ü': nMin:=nMin +1;
 else
  nResto:=nResto +1
 end;
 sMay:= IntToStr(nMay);
 sMin:= intToStr(nMin);
 sDigit:= IntToStr(nDigit);

 ShowMessage(' Longitud String:   ' + IntToStr(nLongi)+#13 // La cadena AEIOU sale como Longitud 7.
             +'MAYÚSCULAS hay :  ' + sMay + #13
             +'minúsculas hay :  ' + sMin + #13
             +' y dígitos hay :  ' + sDigit + #13
             +'El resto:   ' + IntToStr(nResto ));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//Quitar el nombre en la primera línea.
Memo1.Lines[0]:='';
end;
Ya está corregido, se me olvidó usar la función Trim(cString);


La franja horaria es GMT +2. Ahora son las 09:05:23.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi