国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

.NET4.0新功能之String.IsNullOrWhiteSpace() 方法

2019-11-17 04:07:53
字體:
來源:轉載
供稿:網友
在.NET Framework 4.0  中新增加了一些很方便的功能,比如:System.Dynamic支持動態語言運行時、System.Numerics.Complex 復數、System.Numerics.BigInteger 大數、System.Tuple 對象、遍歷文件夾下文件夾和文件的新方法Directory.EnumerateDirectories、Directory.EnumerateFiles、Directory.EnumerateFileSystemEntries等,詳細的新功能列表可以參考下面的鏈接:

http://msdn.microsoft.com/en-us/library/ms171868(VS.100).aspx

同時,還否定了一些原先的功能,這些過時的內容可以參考

http://msdn.microsoft.com/en-us/library/ee461502%28VS.100%29.aspx

下面就是.NET 4.0中新增加的String.IsNullOrWhiteSpace() 方法,方便用戶對字符串進行處理。

C# 代碼
using System;
class TestNET4
{
  static void Main()
  {
    String[] TestString = { null, String.Empty, " ", " ", "abc ", "/t", "/r/n", "/v", "/f", "/a" };
    for (int i = 0; i < TestString.Length; i++)
    {
      String temp = TestString[i];
      if (temp == null)
      {
        Console.WriteLine(" null IsNullOrWhiteSpace = "
                    + String.IsNullOrWhiteSpace(temp).ToString());
      }
      else
      {
        Console.WriteLine(temp + " Length=" + temp.Length.ToString()
              + " IsNullOrWhiteSpace = "
              + String.IsNullOrWhiteSpace(temp).ToString());
      }
    }
  }
}
程序執行結果:

null IsNullOrWhiteSpace = True
Length=0 IsNullOrWhiteSpace = True
  Length=1 IsNullOrWhiteSpace = True
  Length=1 IsNullOrWhiteSpace = True
abc  Length=4 IsNullOrWhiteSpace = False
         Length=1 IsNullOrWhiteSpace = True

Length=2 IsNullOrWhiteSpace = True
Length=1 IsNullOrWhiteSpace = True
Length=1 IsNullOrWhiteSpace = True
Length=1 IsNullOrWhiteSpace = False

IsNullOrWhiteSpace方法的具體實現代碼為:

C# 代碼
public static bool IsNullOrWhiteSpace(string value)
{
    if (value != null)
    {
        for (int i = 0; i < value.Length; i++)
        {
            if (!char.IsWhiteSpace(value[i]))
            {
                return false;
            }
        }
    }
    return true;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吐鲁番市| 象州县| 通山县| 安丘市| 沙坪坝区| 廉江市| 永安市| 海淀区| 长兴县| 太康县| 绥宁县| 郸城县| 瑞昌市| 凤庆县| 子洲县| 荥经县| 秦皇岛市| 华容县| 吉首市| 冀州市| 阿坝县| 法库县| 冷水江市| 大化| 颍上县| 柘城县| 雷波县| 峨眉山市| 饶河县| 来凤县| 中江县| 泸州市| 奉化市| 杭州市| 无极县| 璧山县| 临洮县| 饶河县| 建昌县| 永修县| 虹口区|