Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure DeleteTrash(var S: String);
- var
- Res: String;
- i: Integer;
- IsEmpty: Boolean;
- begin
- { Res := '';
- S := Res + ' ';
- i := 1;
- while (i <= Length(S)) and ((i + 1) <= Length(S)) do
- begin
- if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
- Res := Res + S[i]
- else
- if ((S[i + 1] >= 'a') and (S[i + 1] <= 'z')) or ((S[i + 1] >= 'A') and (S[i + 1] <= 'Z')) then
- Res := Res + ' ';
- Inc(i);
- end;
- if (Res[1] = ' ') and (Length(Res) <> 1) then
- Delete(Res, 1, 1)
- else
- if (Res[1] = ' ') and (Length(Res) = 1) then
- S := '';
- if S[length(S)] <> ' ' then
- S := Res + ' ';
- }
- Res := '';
- S := S + ' ';
- IsEmpty := True;
- for i := 1 to Length(S) do
- if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
- IsEmpty := False;
- if not IsEmpty then
- begin
- i := 1;
- while i <= Length(S) - 1 do
- begin
- if ((S[i] >= 'a') and (S[i] <= 'z')) or ((S[i] >= 'A') and (S[i] <= 'Z')) then
- Res := Res + S[i]
- else
- if ((S[i + 1] >= 'a') and (S[i + 1] <= 'z')) or ((S[i + 1] >= 'A') and (S[i + 1] <= 'Z')) then
- Res := Res + ' ';
- Inc(i);
- end;
- Res := Res + ' ';
- end
- else
- Res := '';
- S := Res;
- end;
Add Comment
Please, Sign In to add comment