国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁乡县| 山东省| 游戏| 宁乡县| 金秀| 福州市| 辽阳县| 盐源县| 睢宁县| 和田市| 许昌市| 垫江县| 门源| 锦屏县| 会理县| 崇明县| 莲花县| 大名县| 尉氏县| 濮阳县| 景德镇市| 峨山| 浏阳市| 华蓥市| 南木林县| 七台河市| 霸州市| 西丰县| 化德县| 高阳县| 吉木萨尔县| 宜兰市| 元朗区| 宜城市| 宣恩县| 上虞市| 常山县| 平武县| 会理县| 大洼县| 绍兴市|