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

C# String Replace高效的實(shí)例方法

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

[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)文章

最新評(píng)論

嵊泗县| 报价| 黎平县| 洛宁县| 健康| 闻喜县| 美姑县| 怀仁县| 昌黎县| 武川县| 洪泽县| 崇仁县| 桦川县| 锡林浩特市| 万安县| 峨眉山市| 米易县| 项城市| 永吉县| 元谋县| 隆昌县| 高邑县| 绍兴市| 囊谦县| 岳池县| 武胜县| 贵州省| 科技| 叶城县| 乌拉特前旗| 遵义市| 泰和县| 宜宾县| 双柏县| 莆田市| 三明市| 澎湖县| 正镶白旗| 会宁县| 根河市| 海晏县|