string.IsNullOrWhiteSpace
测试环境:https://try.dot.net/
Console.WriteLine(string.IsNullOrWhiteSpace("")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace(null)); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\0")); --> False \0 空字符 所以如果输入字符串中含有 \0 这样的单独串,使用 string.IsNullOrWhiteSpace 是应该注意
Console.WriteLine(string.IsNullOrWhiteSpace("\t")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\v")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\r")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\n")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\f")); --> True
Console.WriteLine(string.IsNullOrWhiteSpace("\a")); --> False \a 感叹号
Console.WriteLine(string.IsNullOrWhiteSpace("\b")); --> False \b 退格
Console.WriteLine("123\0"+'d'); --> 123 d
Console.WriteLine(("123\0"+'d').Length); --> 5
Console.WriteLine("\\0"+'d'); --> \0d
Console.WriteLine(@"\0"+'d'); --> \0d
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步