Janilabo Posted October 14, 2012 Share Posted October 14, 2012 (edited) Indents str with spaces (just like the feature in SCAR, Ctrl+Shift+[i/U]). Count is the amount of spaces, and it can be positive value (indent) or negative value (unindent). Included an example with loop for both (indent & unindent): const TEST_STR = ' TESTING Indentation()!' #13 + ' This should work nicely...' #13#10 + ' ..AND IT DOES. '; INDENT_COUNT = 2; function Indentation(str: string; count: Integer): string; var s: string; c: Integer; m: TRegexMatchArray; begin if ((str <> '') and (count <> 0)) then if (count < 1) then begin c := iAbs(count); Result := PregReplace('/(\r\n?|\n|\r)\s{1,' + IntToStr(c) + '}/', #13#10, str); if PregMatchEx('/\A\s{1,' + IntToStr(c) + '}/', Result, m) then begin Delete(Result, m[0].Offset, m[0].Length); SetLength(m, 0); end; end else begin s := StringOfChar(' ', iAbs(count)); Result := PregReplace('/(\r\n?|\n|\r)/', (#13#10 + s), (s + str)); end; end; var str: string; c, i: Integer; begin str := TEST_STR; c := INDENT_COUNT; for i := 1 to 30 do begin ClearDebug; if (i = 10) then c := (IAbs(INDENT_COUNT) * -1); str := Indentation(str, c); WriteLn('Indentation(str, ' + IntToStr(c) + ') [' + IntToStr(i) + '/30]' #13#10#13#10 + str); Wait(100); end; end. Edited October 14, 2012 by Janilabo Quote Link to comment Share on other sites More sharing options...