ToString() public méthode

public ToString ( ) : string
Résultat string
Exemple #1
0
        private static void WhitespaceDiff(StringBuilder res, Word left, Word right)
        {
            if (left.Whitespace == right.Whitespace)
            {
                res.Append(HttpUtility.HtmlEncode(right.ToString()));
            }
            else
            {
                res.Append(HttpUtility.HtmlEncode(right.TheWord));
                char[] leftChars  = left.Whitespace.ToCharArray();
                char[] rightChars = right.Whitespace.ToCharArray();

                Diff diff = new Diff(leftChars, rightChars, Word.Comparer);
                foreach (Diff.Hunk h in diff)
                {
                    if (h.Same)
                    {
                        res.Append(rightChars, h.Right.Start, h.Right.Count);
                    }
                    else
                    {
                        res.Append("<span class='diffchange'>");
                        res.Append('\x00A0', h.Right.Count); // replace spaces with NBSPs to make 'em visible
                        res.Append("</span>");
                    }
                }
            }
        }
        public void WordTests()
        {
            Word w1;
            Word w2;

            w1 = new Word("", "");
            w2 = new Word("", " ");
            Assert.AreEqual("", w1.TheWord);
            Assert.AreEqual("", w1.Whitespace);
            Assert.AreEqual("", w1.ToString());
            Assert.AreEqual("", w2.TheWord);
            Assert.AreEqual(" ", w2.Whitespace);
            Assert.AreEqual(" ", w2.ToString());
            Assert.AreEqual(w1, w2);
            Assert.AreEqual(w1.GetHashCode(), w2.GetHashCode());

            w1 = new Word("foo", "  ");
            w2 = new Word("foo", "");
            Assert.AreEqual("foo", w1.TheWord);
            Assert.AreEqual("foo  ", w1.ToString());
            Assert.AreEqual("foo", w2.ToString());
            Assert.AreEqual(w1, w2);
            Assert.AreEqual(w1.GetHashCode(), w2.GetHashCode());

            w2 = new Word("Foo", "");
            Assert.AreNotEqual(w1, w2);
            Assert.AreNotEqual(w1.GetHashCode(), w2.GetHashCode());
        }
Exemple #3
0
        private static void WhitespaceDiff(StringBuilder res, Word left, Word right)
        {
            if (left.Whitespace == right.Whitespace) res.Append(HttpUtility.HtmlEncode(right.ToString()));
            else
            {
                res.Append(HttpUtility.HtmlEncode(right.TheWord));
                char[] leftChars = left.Whitespace.ToCharArray();
                char[] rightChars = right.Whitespace.ToCharArray();

                Diff diff = new Diff(leftChars, rightChars, Word.Comparer);
                foreach (Diff.Hunk h in diff)
                {
                    if (h.Same)
                        res.Append(rightChars, h.Right.Start, h.Right.Count);
                    else
                    {
                        res.Append("<span class='diffchange'>");
                        res.Append('\x00A0', h.Right.Count); // replace spaces with NBSPs to make 'em visible
                        res.Append("</span>");
                    }
                }
            }
        }