Copy codeThe Code is as follows: [ThreadStatic]
Static char [] mTempChars;
Protected static char [] GetTempData ()
{
If (mTempChars = null)
MTempChars = new char [1024*64];
Return mTempChars;
}
Public static string Replace (string value, string oldData, string newData)
{
Char [] tmpchars = GetTempData ();
Int newpostion = 0;
Int oldpostion = 0;
Int length = value. Length;
Int oldlength = oldData. Length;
Int newlength = newData. Length;
Int index = 0;
Int copylength = 0;
Bool eq = false;
While (index <value. Length)
{
Eq = true;
For (int k = 0; k <oldlength; k ++)
{
If (value [index + k]! = OldData [k])
{
Eq = false;
Break;
}
}
If (eq)
{
Copylength = index-oldpostion;
Value. CopyTo (oldpostion, tmpchars, newpostion, copylength );
Newpostion + = copylength;
Index + = oldlength;
Oldpostion = index;
NewData. CopyTo (0, tmpchars, newpostion, newlength );
Newpostion + = newlength;
}
Else
{
Index ++;
}
}
If (oldpostion <length)
{
Copylength = index-oldpostion;
Value. CopyTo (oldpostion, tmpchars, newpostion, copylength );
Newpostion + = copylength;
}
Return new string (tmpchars, 0, newpostion );
}