Several string processing methods of the struntils Unit
1. dupestring Method
VaR
S: string;
Begin
S: = 'delphi ';
S: = dupestring (s, 3 );
Showmessage (s); // delphidelphidelphi
End;
2. trim, trimlelf, trimright Method
3. rightstr, leftstr Method
VaR
SS, S: string;
Begin
SS: = 'codegear Delphi 2007 ';
S: = rightstr (SS, 4 );
Showmessage (s); {2007}
S: = leftstr (SS, 4 );
Showmessage (s); {code}
End;
4. reversestring Method
VaR
SS, S: string;
Begin
SS: = 'delphi ';
S: = reversestring (SS );
Showmessage (s); {ihpled}
End;
5. quotedstr Method
VaR
SS, S: string;
Begin
SS: = 'delphi ';
S: = quotedstr (SS );
Showmessage (s); {'delphi '}
End;
6. comparestr, comparetext Method
VaR
S1, S2: string;
I: integer;
Begin
S1: = 'abc ';
S2: = 'adpc ';
I: = comparestr (S1, S2 );
Showmessage (inttostr (I); {-2}
I: = comparetext (S1, S2 );
Showmessage (inttostr (I); {-2}
S1: = 'abc ';
S2: = 'abc ';
I: = comparestr (S1, S2); {comparestr case sensitive}
Showmessage (inttostr (I); {32}
I: = comparetext (S1, S2); {comparetext is case insensitive}
Showmessage (inttostr (I); {0}
End;
7. wraptext line feed
VaR
SS, S: string;
Begin
SS: = 'aa. BB e-ff ';
S: = wraptext (SS, #13 #10, ['.', '', #9, '-'], 0 );
Showmessage (s); {AA .}
{Bb}
{E -}
{Ff}
S: = wraptext (SS, #13 #10, ['.', '', #9, '-'], 5 );
Showmessage (s); {AA .}
{BB e -}
{Ff}
S: = wraptext (SS, #13 #10, ['.', '', #9, '-'], 10 );
Showmessage (s); {AA. BB e-ff}
End;
8. uppercase, lowercase Method
VaR
SS, S: string;
Begin
SS: = 'delphi ';
S: = uppercase (SS );
Showmessage (s); // Delphi
S: = lowercase (SS );
Showmessage (s); // Delphi
End;
9. stringreplace Method
VaR
SS, S: string;
Begin
SS: = '2014-2007 ';
S: = stringreplace (SS, '00', 'x', [rfreplaceall]);
Showmessage (s); // 2x7-2x8
S: = stringreplace (SS, '00', 'x', [rfignorecase]);
Showmessage (s); // 2x7-2008
End;
10. isdelimiter-determines whether a position of a string is a specified string.
VaR
S: string;
B: Boolean;
Begin
S: = 'codedear Delphi ';
B: = isdelimiter ('de', s, 3 );
Showmessage (booltostr (B); {-1 is returned, which is true}
End;
11. lastdelimiter-determines the position of a string in another string
VaR
S: string;
I: integer;
Begin
S: = 'codedear Delphi ';
I: = lastdelimiter ('del ', S );
Showmessage (inttostr (I); {12}
End;
12. Format Method
VaR
S: string;
Begin
S: = 'del % s ';
S: = format (s, ['phi ']); {Delphi}
End;