0
\$\begingroup\$

Code:

var i:int=0;
var text:String; 
var compare:String="";
var isFound:boolean=false;
function Start(){
text=AssetDatabase.LoadAssetAtPath("Assets/words.txt",TextAsset).text;
}

function Update(){
    if(!found)
   com("textToSearch");
  }

 function com(s:String){
    if(i<text.Length){
    comText=comText+text[i];
    if(//condition for line break)
    if(comText==s){
       print("found");
       found=true;
    }
   else{
         comText="";
      }
   i++;
   }

 }

In the text document each word ends with a line break. So if I just found a condition for a line break then I can easily search through the document.

\$\endgroup\$
1
\$\begingroup\$

Line breaks are '\n' or '\r\n' depending on the file you are reading.

So your conditions would be something like :

if(myLine.Contains("\n")){
    //DoSomething
}
\$\endgroup\$
2
  • \$\begingroup\$ FWIW, myLine.Contains("\n") will return true anytime myLine.Contains("\r\n") does, so, myLine.Contains("\r\n") is completely unnecessary. \$\endgroup\$ Jul 21 '17 at 14:37
  • \$\begingroup\$ Yes, the idea was to use one of those. It was ambiguous I updated. \$\endgroup\$
    – Shashimee
    Jul 21 '17 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .