コード例 #1
0
        public void Edit(string erased, string replacement)
        {
            int index = Written.LastIndexOf(erased);

            Erase(erased);

            if (string.IsNullOrWhiteSpace(Written.Substring(index, erased.Length)))
            {
                if (replacement.Length == erased.Length)
                {
                    Written = Written.Remove(index, erased.Length).Insert(index, replacement);
                }
                else if (replacement.Length != erased.Length)
                {
                    var sb = new StringBuilder(Written);
                    foreach (char c in replacement)
                    {
                        int i = index + replacement.IndexOf(c);
                        if (char.IsWhiteSpace(Written, i))
                        {
                            sb.Remove(i, 1).Insert(i, c);
                        }
                        else
                        {
                            sb.Remove(i, 1).Insert(i, '@');
                        }
                    }

                    Written = sb.ToString();
                }
            }
        }
コード例 #2
0
        public void Erase(string erased)
        {
            int    index             = Written.LastIndexOf(erased);
            string replacementString = "";

            if (EraserDurability >= erased.Length)
            {
                replacementString = replacementString.PadRight(erased.Length);
                Written           = Written.Remove(index, erased.Length).Insert(index, replacementString);
                EraserDurability -= erased.Length;
            }
            else
            {
                string erasedNew = erased.Substring(0, erased.Length - EraserDurability);
                replacementString = erasedNew + replacementString.PadRight(EraserDurability);
                Written           = Written.Remove(index, erased.Length).Insert(index, replacementString);
                EraserDurability  = 0;
            }
        }