码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-11 21:05:40      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

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);
            }
        }
    }
}

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

标签:

原文地址:http://www.cnblogs.com/candyzhmm/p/5661423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!