I have a list of strings that i check my input against to see if the input contains any of the words within the string list. The issue is, that lets say i have 100 words in my input field. And 99 of those words aren’t in my list, but the last one is. The function is being called 99 times because its returning that all 99 words are ok, except the very last one. How do i wait until all words are checked before proceeding? This is a messaging script. So when a user sends out a message, it checks to see if there are any racial slurs in the text. If the text is ok, then they are good to post it.
IEnumerator PostTextEn()
{
var inputStr = _input.text;
var pieces = inputStr.Split(' ', '.', '\n',','); // consider \n as well if this is multiline
var result = string.Empty;
for (int i = 0, j = 0; i < pieces.Length; i++, j++)
{
j += pieces[i].Length;
for(int p = 0; p < _banned.Count; p++)
{
if(pieces[i].Contains(_banned[p]))
{
_isbanned = true;
_iscomplete = true;
}
else
{
_isbanned = false;
_iscomplete = true;
}
}
}
while(!_iscomplete)
{
yield return null;
}
if(_isbanned)
{
AppManager.VIEW_CONTROLLER.ShowPopupMSG(MessageCode.BannedWord);
}else
{
PostIt();
}
yield return new WaitForEndOfFrame();
}