I have a method called isStringOnlyWhitespace():
public static bool isStringOnlyWhitespace(string toEval)
{
string stringNoWhitespace = Regex.Replace(toEval, @"\s", "");
if (stringNoWhitespace.Length > 0) return false;
else return true;
}
Is there any reason to use this method to check for blank/null strings over String.IsNullOrEmpty()?
Sure, if you are shooting for slower code that is harder to read 🙂
You really want to use
string.IsNullOrWhitespacethough. Whoever wrote that code might have done so before this method existed. But even still, I’d prefermyString.Trim().Length == 0in that case.