Delphi Delete Partial string (case insensitive)

Source: Internet
Author: User

Type
Tdelflags = set of (Dfdelbefore, dfdelafter);

Remove a part of a string that precedes or follows a ENDSTR substring in an MS string

Procedure delstr(var ms:string; endstr:string; Flags:tdelflags;
Bself:boolean = True);
Var
L:integer;
Begin
L: = Length (ENDSTR);
If POS (Ansilowercase (ENDSTR), Ansilowercase (ms)) =0 Then
Begin
Exit
End

If Dfdelbefore in the Flags then
Begin
If Bself Then
Delete (MS, 1, POS (Ansilowercase (ENDSTR), Ansilowercase (ms)) + L-1)
Else
Delete (MS, 1, POS (Ansilowercase (ENDSTR), Ansilowercase (ms))-1)
End
Else
Begin
If Bself Then
Delete (MS, POS (ansilowercase (ENDSTR), Ansilowercase (ms)), Length (ms))
Else
Delete (MS, POS (ansilowercase (ENDSTR), Ansilowercase (ms)) + L, Length (ms))
End
End

Intercepts a partial string between two strings (STR1 and str2) from the SRC main string

function Getcenterstr (src, str1, str2:string): string;

Var
I, I2, I3:integer;
Begin
I: = 0;
I2: = 0;
i3: = 0;
delstr (SRC, str1, [Dfdelbefore]);
I: = pos (Ansilowercase (STR1), ansilowercase (SRC));
i3: = pos (Ansilowercase (STR2), ansilowercase (SRC));
Result: = Copy (src, I2 + 1, i3-i2-1);
End

Delphi Deletes a partial string (case insensitive)

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.