Improve string check.

Avoiding exceptions for empty strings.