No *_* Me 7 c# substring count indexof unity-game-engine
我试图找出“血清素”一词在收集的网络数据中出现的次数,但找不到查找次数的方法。
IEnumerator OnMouseDown()
{
string GatheredData;
StringToFind = "Serotonin"
string url = "https://en.wikipedia.org/wiki/Dopamine";
WWW www = new WWW(url);
yield return www;
GatheredData = www.text;
//Attempted methods below
M1_count = GatheredData.Contains(StringToFind);
M1_count = GatheredData.Count(StringToFind);
M1_count = GatheredData.IndexOf(StringToFind);
}
Run Code Online (Sandbox Code Playgroud)
当我告诉它索引和方法 2 中的哪个数字有效但仅适用于字符而不适用于字符串时,我可以轻松使用来自方法 1 和方法 3 的数据
我已经在网上和这里检查过,但没有发现找到 StringToFind 的计数
Sai*_*aif 12
假设字符串是这样的
string test = "word means collection of chars, and every word has meaning";
Run Code Online (Sandbox Code Playgroud)
然后只需使用正则表达式来查找单词在您的test字符串中匹配的次数,如下所示
int count = Regex.Matches(test, "word").Count;
Run Code Online (Sandbox Code Playgroud)
输出将是 2