Page 1/2 of the five methods for string replacement in ASP. NET

Source: Internet
Author: User

1: Use the string. replace function, but the case is not supported.
2: replace system. Text. RegEx with the regular expression "regexpoption" to check whether case sensitivity is supported.
3: Use string. substring and + to indirectly replace small data.
4: importing microsoftvisualbasicruntime (Microsoft. VisualBasic. dll) using strings. Replace is fast.
5: refer to the reflection reflector. filedisassembler and strings. splitandstrings. Join implementation. The speed is the same as 5.
A Algorithm , Similar to the KMP algorithm. If you are interested, refer to the study.
Reference content is as follows: CopyCode The Code is 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 );
}

Related Article

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.