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