判断某个字或词在字符串中出现的次数

-- a 在 b 中出现的次数

var a = "xx";

var b = "xxyyxxbbccxx";

-- js:

function fnGetCount(a, b){

  return (b.length - b.replace(new RegExp(a,"gm"),'').length) / a.length;

}

// C#

public int fnGetCount(string a, string b)

{

  return (b.Length - b.Replace(a,"").Length) / a.Length;

}

 

posted @ 2021-03-23 10:22  Vaynedy  阅读(13)  评论(0)    收藏  举报