- Home /
How to check if the string is on a text file
I am trying to check if the string from a UI text is in the text file. Am I doing the right thing or should I use Dictionary or List to fix this. if yes how would I be doing it to check if the string is in the text file?
 using UnityEngine;
 using UnityEngine.UI;
 using System.Linq;
 
 public class wordChecker : MonoBehaviour {
 
     public string[] textFile = "wordlist.txt".Split('\n');
     string[] txtContents;
     public Text WordCreated;
 
 
     private void Start()
       {
           TextAsset txtAsset = (TextAsset)Resources.Load("wordlist");
           txtContents = txtAsset.text.Split('\n');
       }
 
       public void checkword()
       {
         
         if (txtContents.Contains(WordCreated.text))
               {
                   Debug.Log("Its on the list");
               }
               else
               {
                   Debug.Log("Someting is wrong..");
               }
 
       } 
 
               Comment
              
 
               
              The split is unnecessary, you can do Contains on a string directly.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                