【转载】C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别
在C#中判断字段是否为空或者Null的时候,我们一般会使用到string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法,这两个方法在大部分情况下判断的结果是一致的,但相比于string.IsNullOrEmpty方法,string.IsNullOrWhiteSpace方法还会对空白字符进行判断,例如一个字符串全是空格等空白字符的情况,在string.IsNullOrEmpty的判断下为false,而string.IsNullOrWhiteSpace方法判断则为true。
举例如下:
string stringD = " ";//空白字符串
var resultD1 = string.IsNullOrEmpty(stringD);
var resultD2= string.IsNullOrWhiteSpace(stringD);
上述语句的结果resultD1=false,resultD2=true。string.IsNullOrWhiteSpace方法认定为这种空白字符也是符合规则的,因此返回true。
备注:原文转载自博主个人站IT技术小趣屋,原文链接为C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别_IT技术小趣屋。
【转载】C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别的更多相关文章
- C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)
一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...
- 1,字符是否为空,2,比较两个字符大小。String.Compare(String, String)。string.IsNullOrEmpty(string)
1, String.Compare 方法 (String, String) 比较两个指定的 String 对象. 值 条件 小于零 strA 小于 strB. 零 strA 等于 strB. 大于零 ...
- string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的区别
string.IsNullOrEmpty 都知道,这个功能是判断字符串是否为:null或者string.Empty.如果是如"\t"这样的字符就返回false了,为了达到判断过滤这 ...
- String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()
转自:http://hi.baidu.com/saclrpqmttbntyq/item/4592fc72c5a19e5c0d0a07eb 由于总用 String.IsNullOrEmpty( s ) ...
- String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()的区别
string.IsNullOrEmpty 这个是判断字符串是否为:null或者string.Empty或者“”,但不包含空格 .如果是如"\t"或者“ ” 这样的字符就返回fa ...
- String.IsNullOrEmpty 与 String.IsNullOrWhiteSpace
String.IsNullOrEmpty 指示指定的字符串是否为 null 或者 空字符串: 返回值:如果参数为 null 或者 空字符串("" .String.Empty),结果 ...
- 转载JQuery 中empty, remove 和 detach的区别
转载 http://www.cnblogs.com/lisongy/p/4109420.html .empty() 描述: 从DOM中移除集合中匹配元素的所有子节点. 这个方法不接受任何参数. 这个 ...
- 转载 Python中关键字global与nonlocal的区别
转载自CSDN 雁丘1990, 原文地址: https://blog.csdn.net/xcyansun/article/details/79672634 这篇文章写的很赞, 条理清晰, 分析循序渐进 ...
- [转载]C++中 引用&与取地址&的区别
一个是用来传值的 一个是用来获取首地址的 &(引用)==>出现在变量声明语句中位于变量左边时,表示声明的是引用. 例如: int &rf; // 声明一个int型的引用r ...
随机推荐
- Java 自定义异常
新建类CustomException继承 Exception /** * Create by on 2019-07-30 * 自定义类需要继承Exception * @author lsw */ pu ...
- Verticles for Web Application
Core Concept: HTTP-Centered EventBus Event, EventLoop, Executor, Handler, HTTPContext, Callback on E ...
- #C++初学记录(ACM8-6-cf-f题)
F. Vanya and Label While walking down the street Vanya saw a label "Hide&Seek". Becaus ...
- 性能测试指标:TPS,吞吐量,并发数,响应时间
性能测试指标:TPS,吞吐量,并发数,响应时间 常用的网站性能测试指标有:TPS.吞吐量.并发数.响应时间.性能计数器等. 并发数并发数是指系统同时能处理的请求数量,这个也是反应了系统的负载能力. 响 ...
- typescript - 9.装饰器
装饰器:装饰器是一种特殊类型的声明,它能够被附加到类声明,方法,属性或参数上,可以修改类的行为. 通俗的讲装饰器就是一个方法,可以注入到类.方法.属性参数上来扩展类.属性.方法.参数的功能. 常见的装 ...
- date命令时间戳和时间之间的转换
这里是在mac下的操作,主要就是用date这个命令,更多的用法用man命令查看 字符串格式时间 TO 时间戳我们知道date 命令可以直接把当前时间转化为时间戳 # date +%s143678152 ...
- MD5(3)
import java.io.UnsupportedEncodingException; import java.security.PrivateKey; import java.security.S ...
- react 模板备份
/** * Created by hldev on 17-6-14. * 上市公司详情展示界面 */ import React, {Component} from "react"; ...
- Bcrypt.check_pass/3 用法
defmodule My do defstruct password: "", apassword_hash: "", aencrypted_password: ...
- K8S+GitLab+.net core-自动化分布式部署-1
K8S+GitLab-自动化分布式部署ASP.NET Core(一) 部署环境 一.部署流程介绍 开发人员通过Git上传asp.net core 项目到Gilab,并编写好.gitlab-ci.yml ...