Advertisement
r4lovets

Untitled

Jan 7th, 2019
2,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure DeleteTrash(var S: String);
  2.  
  3. var
  4.   Res: String;
  5.   i: Integer;
  6.   IsEmpty: Boolean;
  7.  
  8. begin
  9. {  Res := '';
  10.   S := Res + ' ';
  11.  
  12.   i := 1;
  13.   while (i <= Length(S)) and ((i + 1) <= Length(S)) do
  14.     begin
  15.       if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
  16.         Res := Res + S[i]
  17.       else
  18.         if ((S[i + 1] >= 'a') and (S[i + 1] <= 'z')) or ((S[i + 1] >= 'A') and (S[i + 1] <= 'Z')) then
  19.           Res := Res + ' ';
  20.       Inc(i);
  21.     end;
  22.  
  23.   if (Res[1] = ' ') and (Length(Res) <> 1) then
  24.     Delete(Res, 1, 1)
  25.   else
  26.     if (Res[1] = ' ') and (Length(Res) = 1) then
  27.       S := '';
  28.  
  29.   if S[length(S)] <> ' ' then
  30.     S := Res + ' ';
  31. }
  32.  
  33.   Res := '';
  34.   S := S + ' ';
  35.  
  36.   IsEmpty := True;
  37.   for i := 1 to Length(S) do
  38.     if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
  39.       IsEmpty := False;
  40.  
  41.   if not IsEmpty then
  42.     begin
  43.       i := 1;
  44.       while i <= Length(S) - 1 do
  45.         begin
  46.           if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
  47.             Res := Res + S[i]
  48.           else
  49.             if ((S[i + 1] >= 'a') and (S[i + 1] <= 'z')) or ((S[i + 1] >= 'A') and (S[i + 1] <= 'Z')) then
  50.               Res := Res + ' ';
  51.           Inc(i);
  52.         end;
  53.       Res := Res + ' ';
  54.     end
  55.   else
  56.     Res := '';
  57.  
  58.   S := Res;
  59.  
  60. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement