Several string processing methods of the struntils Unit

Source: Internet
Author: User
Tags stringreplace

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.