Простой способ удаления двойных, тройных и т.д. пробелов — Pascal(Паскаль)

CONST
  FileName: String = 'Strings.txt';
  S: String = ' sadfghj D Gajds ghs ASDHJg        sdhgjhsad   ';
VAR
  f: Text;
  S: String;
BEGIN
  Assign(f, FileName); {$I-}Reset(f); {$I+}
  if IOResult = 0 then begin ReadLn(f, S); Close(f) end;
  WriteLn(S);
  while (POS('  ', S) > 0) do delete(S, POS('  ',S), 1);
  {Первый и последний пробелы}
  if (lenght(S) > 1) and (S[1] = ' ') then Delete(S, 1, 1);
  if (length(S)>1) and (S[length(S)] = ' ') then Delete(S, length(S), 1);
END.

Leave a Comment

− 2 = 2