asp.Netは1つの文字列が別の文字列に存在する回数を判断する
974 ワード
/// <summary>
/// formString ToString
/// </summary>
/// <param name="formString"></param>
/// <param name="ToString"></param>
/// <returns></returns>
/// https://msdn.microsoft.com/zh-cn/library/bb546166.aspx
public static int ToFrequency(string formString, string ToString)
{
if (string.IsNullOrWhiteSpace(formString) || string.IsNullOrWhiteSpace(ToString))
{
return 0;
}
formString = formString.ToLower();
ToString = ToString.ToLower();
var source = ToString.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',','\'','"' }, StringSplitOptions.RemoveEmptyEntries);
return source.Count(c=>c.Equals(formString));
}