Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exactly match a word with C#'s contains function?

Tags:

c#

contains

I am trying to read out scripts through C# and determine if they contain certain words, but these words should be identical to instead of only containing what I'm looking for. Is there a way to use the contains-function, single out the word, and check if it is identical to the exact word?

How can I determine if it both contains and is identical to the search term?

Currently I am using the following script:

// GetScriptAssetsOfType<MonoBehaviour>() Returns all monobehaviour scripts as text
foreach (MonoScript m in GetScriptAssetsOfType<MonoBehaviour>())
{
    if (m.text.Contains("Material"))
    {
       // Identical check?
    }
}
like image 493
MX D Avatar asked Sep 24 '14 09:09

MX D


1 Answers

How about a regex?

bool contains = Regex.IsMatch(m.text, @"\bMaterial\b");
like image 121
artm Avatar answered Nov 08 '22 13:11

artm