How do I exactly match a word with C#'s contains function?
16,345
How about a regex?
bool contains = Regex.IsMatch(m.text, @"\bMaterial\b");
Author by
MX D
I'm a game developer with a passion for programing. I mainly use C# and the Unity3D engine, but my knowledge is not limited to this. My hobby's are gaming, anime/manga and learning new things.
Updated on September 16, 2022Comments
-
MX D over 1 year
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? } }