예제 #1
0
        public void StartWithTheseTest_CollectionString()
        {
            Assert.False(StringJudgment.StartWithThese("0", new List <string> {
                "1", "2"
            }));
            Assert.False(StringJudgment.StartWithThese("123", new List <string> {
                "", ""
            }));
            Assert.False(StringJudgment.StartWithThese("1234", new List <string> {
                "234", "23"
            }));
            Assert.False(StringJudgment.StartWithThese("23", new List <string> {
                "234", "3"
            }));
            Assert.False(StringJudgment.StartWithThese("123", new List <string> {
                null, null
            }));
            Assert.False(StringJudgment.StartWithThese("", new List <string> {
                "", ""
            }));
            Assert.False(StringJudgment.StartWithThese("", new List <string> {
                null, null
            }));
            Assert.False(StringJudgment.StartWithThese(null, new List <string> {
                "", ""
            }));
            Assert.False(StringJudgment.StartWithThese(null, new List <string> {
                null, null
            }));
            Assert.False(StringJudgment.StartWithThese(null, new List <string> {
                "", null
            }));
            Assert.False(StringJudgment.StartWithThese("", new List <string> {
                "", null
            }));

            Assert.True(StringJudgment.StartWithThese("1234", new List <string> {
                "1", "12", "123", "234", "34", "4"
            }));
            Assert.True(StringJudgment.StartWithThese("1234", new List <string> {
                "1234", "123", "12", "1"
            }));

            List <string> nullList = new List <string>();

            nullList = null;
            Assert.False(StringJudgment.StartWithThese("", nullList));
        }
예제 #2
0
        public void StartWithTheseTest_SingleString()
        {
            Assert.False(StringJudgment.StartWithThese("0", "1"));
            Assert.False(StringJudgment.StartWithThese("123", ""));
            Assert.False(StringJudgment.StartWithThese("1234", "234"));
            Assert.False(StringJudgment.StartWithThese("23", "234"));
            Assert.False(StringJudgment.StartWithThese("123", null));
            Assert.False(StringJudgment.StartWithThese("", null));
            Assert.False(StringJudgment.StartWithThese(null, ""));
            Assert.False(StringJudgment.StartWithThese(null, null));
            Assert.False(StringJudgment.StartWithThese("", ""));

            Assert.True(StringJudgment.StartWithThese("1234", "1"));
            Assert.True(StringJudgment.StartWithThese("1234", "1234"));
            Assert.True(StringJudgment.StartWithThese("12345678", "1234"));
        }
예제 #3
0
        public void StartWithTheseTest_MutliStrings()
        {
            Assert.False(StringJudgment.StartWithThese("0", "1", "2"));
            Assert.False(StringJudgment.StartWithThese("123", "", ""));
            Assert.False(StringJudgment.StartWithThese("1234", "234", "23"));
            Assert.False(StringJudgment.StartWithThese("23", "234", "3"));
            Assert.False(StringJudgment.StartWithThese("123", null, null));
            Assert.False(StringJudgment.StartWithThese("", "", ""));
            Assert.False(StringJudgment.StartWithThese("", null, null));
            Assert.False(StringJudgment.StartWithThese(null, "", ""));
            Assert.False(StringJudgment.StartWithThese(null, null, null));
            Assert.False(StringJudgment.StartWithThese(null, "", null));
            Assert.False(StringJudgment.StartWithThese("", "", null));

            Assert.True(StringJudgment.StartWithThese("1234", "1", "12", "123", "234", "34", "4"));
            Assert.True(StringJudgment.StartWithThese("1234", "1234", "123", "12", "1"));
        }
 /// <summary>
 /// 头部匹配
 /// </summary>
 /// <param name="string">字符串</param>
 /// <param name="values">字符串数组</param>
 public static bool StartsWith(this string @string, ICollection <string> values) =>
 StringJudgment.StartWithThese(@string, values);
 /// <summary>
 /// 头部匹配
 /// </summary>
 /// <param name="string">字符串</param>
 /// <param name="values">字符串数组</param>
 public static bool StartsWith(this string @string, params string[] values) =>
 StringJudgment.StartWithThese(@string, values);