Example #1
0
        public void StringToCharArrayRange()
        {
            //                   00000000000111111111222222
            //                   01234567890123456789012345
            const string text = "Lorem ipsum dolor sit amet";

            char[] expected = "ipsum dolor".ToCharArray();

            char[] result = String2.ToCharArray(text, 6, 11);
            Assert.AreEqual(expected.Length, result.Length);
            if (!result.SequenceEqual(expected))
            {
                Assert.Fail("String range char array test #1");
            }

            expected = "Lorem ipsum".ToCharArray();
            result   = String2.ToCharArray(text, 0, 11);
            Assert.AreEqual(expected.Length, result.Length);
            if (!result.SequenceEqual(expected))
            {
                Assert.Fail("String range char array test #2");
            }

            expected = "sit amet".ToCharArray();
            result   = String2.ToCharArray(text, 18, 8);
            Assert.AreEqual(expected.Length, result.Length);
            if (!result.SequenceEqual(expected))
            {
                Assert.Fail("String range char array test #3");
            }
        }