Title: Special trimming strings functions.
Question: Trim & Co. are not always complete: somethimes you must remove other chars than #32 (white space). There are some special functions.
Answer:
This returns the What string removing initials WhatChar chars.
Function SpLTrim( What : String; WhatChar : Char = #32 ) : String;
Var
IdX : Integer;
Begin
Result := What;
If ( Length( What ) 0 ) Then Begin
For IdX := 1 To Length( What ) Do
If ( What[ IdX ] WhatChar ) Then Break;
If ( IdX 1 ) Then Result := Copy( What, IdX, MaxInt );
End;
End;
This returns the What string removing final WhatChar chars.
Function SpRTrim( What : String; WhatChar : Char = #32 ) : String;
Var
IdX : Integer;
Begin
Result := What;
If ( Length( What ) 0 ) Then Begin
For IdX := Length( What ) DownTo 1 Do
If ( What[ IdX ] WhatChar ) Then Break;
If ( IdX 1 ) Then Result := Copy( What, 1, IdX );
End;
End;
This returns the What string removing initials and final WhatChar chars.
Function SpTrim( What : String; WhatChar : Char = #32 ) : String;
Begin
Result := SpLTrim( SpRTrim( What, WhatChar ), WhatChar );
End;