<h3>модуль</h3>
unit SpaceLib;
interface
uses System;
const
ch = ' ';
function MyTrimLeft(s: string): string;
function MyTrimRight(s: string): string;
function MyTrim(s: string): string;
function MySingleSpaces(s: string): string;
function MyNoSpaces(s: string): string;
implementation
function MyTrimLeft(s: string): string;
begin
MyTrimLeft := Regex.Replace(s, '^[' + ch + ']+', '');
end;
function MyTrimRight(s: string): string;
begin
MyTrimRight := Regex.Replace(s, '[' + ch + ']+$', '');
end;
function MyTrim(s: string): string;
begin
s := Regex.Replace(s, '^[' + ch + ']+', '');
MyTrim := Regex.Replace(s, '[' + ch + ']+$', '');
end;
function MySingleSpaces(s: string): string;
begin
s := MyTrim(s);
MySingleSpaces := Regex.Replace(s, '[' + ch + ']+', ' ');
end;
function MyNoSpaces(s: string): string;
begin
MyNoSpaces := s.Replace(ch, '');
end;
end.
<h3>Пример</h3>
//PascalABC.NET версия 3.4.0.1677 от 17.06.18
//Если программа не запускается, то обновите версию
uses SpaceLib;
begin
var s := ' 123 123 23 4343 434 43 34 ';
WritelnFormat('"{0}"', MyTrimLeft(s));
WritelnFormat('"{0}"', MyTrimRight(s));
WritelnFormat('"{0}"', MyTrim(s));
WritelnFormat('"{0}"', MySingleSpaces(s));
WritelnFormat('"{0}"', MyNoSpaces(s));
end.
<h3 />