在C#中,可以使用以下方法来判断字符串是否为空:
string str = "test";
if (String.IsNullOrEmpty(str))
{
Console.WriteLine("String is null or empty.");
}
else
{
Console.WriteLine("String is not null or empty.");
}
string str = "test";
if (String.IsNullOrWhiteSpace(str))
{
Console.WriteLine("String is null, empty, or consists only of white-space characters.");
}
else
{
Console.WriteLine("String is not null, empty, or consists only of white-space characters.");
}
这两种方法可以帮助您确定字符串是否为空或仅包含空格或制表符等空白字符。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言怎么判断字符串是否为空