string.IsNullOrEmpty

都知道,这个功能是判断字符串是否为:null或者string.Empty。如果是如"\t"这样的字符就返回false了,为了达到判断过滤这些功能,就要使用Trim()和Length属性帮忙,判断是否长度为零,于是乎就产生了如下的方法。

string.IsNullOrWhiteSpace

这个是判断所有空白字符,功能相当于string.IsNullOrEmpty和str.Trim().Length总和,他将字符串给Char.IsWhiteSpace为ture的任何字符都将是正确的。根据MSDN的说明,这个方法会比调用上述两个方法的性能更高而且简洁,所以在判断这个功能时,推荐使用。

using System;

public class Example
{
public static void Main()
{
string[] values = { null, String.Empty, "ABCDE",
new String(' ', ), " \t ",
new String('\u2000', ) };
foreach (string value in values)
Console.WriteLine(String.IsNullOrWhiteSpace(value));
}
}
// The example displays the following output:
// True
// True
// False
// True
// True
// True

string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的区别的更多相关文章

  1. 【转载】C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别

    在C#中判断字段是否为空或者Null的时候,我们一般会使用到string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法,这两个方法在大部分情况下判断的结果是一致的 ...

  2. C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)

    一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...

  3. String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()的区别

    string.IsNullOrEmpty 这个是判断字符串是否为:null或者string.Empty或者“”,但不包含空格 .如果是如"\t"或者“   ” 这样的字符就返回fa ...

  4. String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()

    转自:http://hi.baidu.com/saclrpqmttbntyq/item/4592fc72c5a19e5c0d0a07eb 由于总用 String.IsNullOrEmpty( s ) ...

  5. String的几种初始化方法的区别

    参考了: java中String的两种初始化方法   String a; String aa = ""; String aaa = "123"; String ...

  6. String.IsNullOrEmpty 与 String.IsNullOrWhiteSpace

    String.IsNullOrEmpty 指示指定的字符串是否为 null 或者 空字符串: 返回值:如果参数为 null 或者 空字符串("" .String.Empty),结果 ...

  7. 1,字符是否为空,2,比较两个字符大小。String.Compare(String, String)。string.IsNullOrEmpty(string)

    1, String.Compare 方法 (String, String) 比较两个指定的 String 对象. 值 条件 小于零 strA 小于 strB. 零 strA 等于 strB. 大于零 ...

  8. String.IsNullOrWhiteSpace和String.IsNullOrEmpty的区别

    以前刚入行的时候判断字符串的时候用 string a="a"; a==""; a==null; 后来发现了String.IsNullOrEmpty感觉方便了好多 ...

  9. 【源码分析】你必须知道的string.IsNullOrEmpty && string.IsNullOrWhiteSpace

    写在前面 之前自信撸码时踩了一次小坑,代码如下: private static void AppServer_NewMessageReceived(WebSocketSession session, ...

随机推荐

  1. Atitit。数据库 安全性 重要敏感数据加密存储解决方案

    Atitit.数据库 安全性 重要敏感数据加密存储解决方案 1.1. 加密存储的重要性1 1.2. 使用的加密算法aes1 1.3. 数据加密以后会有一些问题.1 1.3.1. 一个是统计,比如统计资 ...

  2. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q139-Q141)

    Question 139You create a SharePoint solution that contains two Features named Feature1 and Feature2. ...

  3. Nginx中文详解、配置部署及高并发优化

      一.Nginx常用命令: 1. 启动 Nginx          /usr/local/nginx/sbin/nginxpoechant@ubuntu:sudo ./sbin/nginx2. 停 ...

  4. React Native常用组件Image使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  5. Android measure过程分析

    作为一名Android开发人员,我们都知道一个View从无到有,会经历3个阶段: 1. measure/测量阶段,也就是确定某个view大小的过程: 2. layout/布局阶段,也就是确定其左上右下 ...

  6. svn的使用(转载)

    这里只介绍使用CornerStone来使用SVN. CornerStone是Mac OS X系统下非常好用的一款svn工具,当然还有Versions也是可以用的,但是使用起来不如CornerStone ...

  7. 敏捷开发与jira之研发管理模式

    以IPD方法论为基础,采用原型+迭代的开发模式,并以质量优先为原则,持续对用户做价值交付. 使用JIRA+WIKI+SVN管理整个的研发过程:JIRA管理任务和进度:SVN管理代码和过程文档:WIKI ...

  8. VS的安装

    一 安装过程 我直接在官网下载的 2015版本 ,软件比较大 安装起来比较花时间 同时也装了中文语言包,下面附上安装过程中的一些截图. 二 现在正在摸索如何使用,百度教程,等会附上单元测试.

  9. CouchDB简介

    类型:开源数据库,Apache项目 存储格式:JSON 查询语言:JavaScript API :MapReduce.HTTP 特点 MVCC(Multiversion concurrency con ...

  10. AutoMySQLBackup 3.0 Bug:"du: WARNING: use --si, not -H"

    案例环境: 操作系统版本: Red Hat Enterprise Linux Server release 5.7 64bit 数据库版本 : 5.6.19 MySQL Community Serve ...