If String only contains spaces

Hi, is there a way to check a string to see if it only contains spaces ?

You use string.IsNullOrWhiteSpace.

But because Mono isn’t using the newest version of .NET. you’ll have to implement it yourself:

public bool ConsistsOfWhiteSpace(string s){
    foreach(char c in s){
        if(c != ' ') return false;
    }
    return true;

}

if (value.Trim().Length == 0)
Debug.Log(“empty”);
else
Debug.Log(“not empty”);

Theoretically, it should be something like this:

bool atLeastOneNotspace = false;

for(int i =0; i < someString.Lenght; i++){
   if(!(someString *== " ")){*

atLeastOneNotspace = true;
break;
}
}

if(!atLeastOneNotspace) Debug.Log(“Is empty”);

I just saw this now. If you’re going to iterate thru the entire char of the string, I suggest you use char.IsWhiteSpace instead of == " "

foreach(char c in text)
{
    if(char.IsWhiteSpace(c) == false)
    {
        return false;
     }
}