in ASP. Five methods of string substitution in net 1th/2 page _ Practical Tips

Source: Internet
Author: User
1: Replace with the String.Replace function, but not case-supported.
2: Regular System.Text.Regex replacement, with regexpoption modify whether or not to support case.
3: In the case of small data, the use of string.substring and + can achieve indirect replacement.
4: Import microsoftvisualbasicruntime (Microsoft.VisualBasic.DLL) use strings.replace speed quickly.
5: The reference reflection Reflector.filedisassembler cooperate with Strings.SplitandStrings.Join and so on, the speed is same as 5.
This paper introduces an algorithm similar to KMP algorithm. Interested in the study under the reference.
The following are the referenced contents:
Copy Code code as follows:

Privatestaticstringreplaceex (Stringoriginal,
Stringpattern,stringreplacement)
{
Intcount,position0,position1;
count=position0=position1=0;
Stringupperstring=original. ToUpper ();
Stringupperpattern=pattern. ToUpper ();
Intinc= (original. Length/pattern. Length) *
(Replacement. Length-pattern.length);
Char[]chars=newchar[original. Length+math.max (0,inc)];
while (Position1=upperstring.indexof (Upperpattern,
Position0))!=-1)
{
for (Inti=position0;i<position1;++i)
Chars[count++]=original[i];
For (inti=0;i<replacement. Length;++i)
Chars[count++]=replacement[i];
Position0=position1+pattern. Length;
}
if (position0==0) returnoriginal;
For (inti=position0;i<original. Length;++i)
Chars[count++]=original[i];
Returnnewstring (Chars,0,count);
}

Current 1/2 page 12 Next read the full text

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.