function StringConvert(S: string): string;
var
L, I, J: Integer;
begin
Result := EmptyStr;
L := Length(S);
if L = 0 then
Exit;
I := 1;
repeat
if (S[I] >= ' ') and (S[I] <> '''') and (Ord(S) <= 127) then
begin
J := I;
repeat
Inc(I)
until (I > L) or (S[I] < ' ') or (S[I] = '''') or (Ord(S) > 127);
Result := Result + '''';
while J < I do
begin
Result := Result + string(AnsiChar(S[J]));
Inc(J);
end;
Result := Result + '''';
end
else
begin
Result := Result + '#' + IntToStr(Ord(S[I]));
Inc(I);
end;
until I > L;
end;