WordCount() public static method

지정된 문자열에 지정된 문자들의 갯수를 구한다.
public static WordCount ( string s ) : int
s string 대상 문자열
return int
Exemplo n.º 1
0
 public void WordCountTest()
 {
     Assert.AreEqual(2, StringTool.WordCount(S3, "이"));
     Assert.AreEqual(4, StringTool.WordCount(S1, "F"));
     Assert.AreEqual(4, StringTool.WordCount(S1, "f"));
     Assert.AreEqual(0, StringTool.WordCount(S1, "f", false));
 }
Exemplo n.º 2
0
        public void ReplaceTest()
        {
            int count = 100;

            var sb = new StringBuilder(S3.Length * count);

            for (int i = 0; i < count; i++)
            {
                sb.AppendLine(S3);
            }

            string largeStr = sb.ToString();

            Assert.AreEqual(count * 2, StringTool.WordCount(largeStr, "동해물"));

            string replaced = largeStr.Replace("동해물", "서해물", true);

            Assert.AreEqual(0, StringTool.WordCount(replaced, "동해물"));
            Assert.AreEqual(count * 2, StringTool.WordCount(replaced, "서해물"));
        }