• (转载)String.IsNullorEmpty()方法的使用


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace StringIsNull
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string s1 = "abcd";
                string s2 = "";
                string s3 = null;
                string s4 = " ";

                Response.Write(string.Format("String s1 {0}.", Test(s1)) + "<br />");
                Response.Write(string.Format("String s2 {0}.", Test(s2)) + "<br />");
                Response.Write(string.Format("String s3 {0}.", Test(s3)) + "<br />");
                Response.Write(string.Format("String s4 {0}.", Test(s4)) + "<br />");
            }
            public static String Test(string s)
            {
                if (String.IsNullOrEmpty(s))
                {
                    return "is null or empty";
                }
                else if(String.IsNullOrEmpty(s.Trim()))
                {
                    return "its Trim is null or empty";
                }
                else
                {
                    return String.Format("("{0}") is not null or empty", s);
                }
            }
        }
    }
  • 相关阅读:
    C++ ORM ODB 入门(三)
    C++ ORM ODB 入门介绍(二)
    最简便的MySql数据库备份方法
    快速高效的破解MySQL本地和远程密码
    C++ ORM ODB 入门介绍(一)
    NeHe OpenGL教程 第三十九课:物理模拟
    NeHe OpenGL教程 第三十八课:资源文件
    NeHe OpenGL教程 第三十七课:卡通映射
    NeHe OpenGL教程 第三十六课:从渲染到纹理
    NeHe OpenGL教程 第三十五课:播放AVI
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/5661423.html
Copyright © 2020-2023  润新知