Ver Mensaje Individual
  #1  
Antiguo 22-03-2014
Avatar de bulc
bulc bulc is offline
Miembro
 
Registrado: jun 2010
Posts: 415
Reputación: 14
bulc Va por buen camino
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);

Última edición por bulc fecha: 22-03-2014 a las 18:37:48.
Responder Con Cita