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 );
}