小编No *_* Me的帖子

在字符串 C# 中查找子字符串的计数

我试图找出“血清素”一词在收集的网络数据中出现的次数,但找不到查找次数的方法。

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 的计数

c# substring count indexof unity-game-engine

7
推荐指数
1
解决办法
9743
查看次数

标签 统计

c# ×1

count ×1

indexof ×1

substring ×1

unity-game-engine ×1