最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# String Replace高效的實例方法

 更新時間:2013年05月01日 13:56:52   作者:  
C# String Replace高效的實例方法,需要的朋友可以參考一下
復制代碼 代碼如下:

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

相關(guān)文章

最新評論

克拉玛依市| 那坡县| 遂川县| 濉溪县| 任丘市| 饶河县| 唐河县| 西平县| 宜良县| 宣化县| 清徐县| 临汾市| 枣强县| 柏乡县| 昌平区| 淳安县| 余江县| 扬州市| 义马市| 抚远县| 河曲县| 焉耆| 东光县| 顺平县| 吴堡县| 蒲城县| 彭阳县| 日喀则市| 中超| 榆林市| 宜川县| 南昌市| 榆社县| 武隆县| 余姚市| 堆龙德庆县| 北川| 江达县| 汝城县| 宁海县| 曲水县|