c# - string.IsNullOrEmpty 使用 Trim()

标签 c# string trim isnullorempty

我想删除第一行:

                 !string.IsNullOrEmpty(cell.Text) 

这会导致任何问题吗?

我在一些代码中遇到过这个:

                if ((id % 2 == 0)
                    && !string.IsNullOrEmpty(cell.Text)
                    && !string.IsNullOrEmpty(cell.Text.Trim())
                    )

我认为第一个 string.IsNullOrEmpty 会在带空格的字符串上返回 false
带有 Trim() 的行会处理这个问题,所以第一个 IsNullOrEmpty 是无用的

但在我删除没有修剪的线之前,我想我应该由小组运行它。

最佳答案

如果 cell.Text 为 null,则没有第一次检查就会出现异常。

关于c# - string.IsNullOrEmpty 使用 Trim(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707288/

相关文章:

c# - 如何使用表单例份验证锁定用户

c# - 仅接受从特定服务器到我的 asp.net 页面的请求

c++ - 取而代之的是获取存储的内存编号

python - 如何将字符串转换为数据框,指定列数?

php - 为什么 trim 不能作为 PHP 中 array_walk 或 array_map 的回调?

java - 修剪文本 - 当最后输入大量空格键时

c# - 机器特定的 HttpWebResponse 超时

python - `filter()` 在 Python 2.x 和 3.x 之间有变化吗?

xcode - 修剪 Xcode 中的尾随空格

c# - AWS Elasticsearch Service - 手动快照到 S3