using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Work5
{
class Program
{
static void Main(string[] args)
{
string str = "qabaabbwerabtyababuiopasdfghjkabl";
Dictionary<string, int> dic = new Dictionary<string, int>();
string str1 = "";
for (int i = 0; i < str.Length;i++ )
{
for (int j = 2; j <= str.Length-i;j++ )
{
//截取不同长度的字符串
str1 = str.Substring(i,j);
//所截取的字符串包含,键值在原有的基础上加1
if (dic.ContainsKey(str1))
{
dic[str1] = dic[str1] + 1;
}
else
{
dic.Add(str1,1);
}
}
}
//遍历结果集
foreach (string key in dic.Keys)
{
if (dic[key] > 1)
{
Console.WriteLine("{0}出现的次数为:{1}",key,dic[key]);
}
}
Console.ReadKey();
}
}
}