程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#制表符過濾處理方法

C#制表符過濾處理方法

編輯:C#入門知識

C#制表符過濾處理方法


C#制表符過濾處理方法,動態替換字符串裡面的制表符。

 

    /// 
    /// Descrioption:
    ///需要替換字符集合,可參見MSDN
    /// The Trim method only trims 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0085, 0x2028, and 0x2029.
    /// This array adds in control characters.
    /// Author     : 付義方
    /// Create Date: 2014-03-06
    /// 
    public static readonly char[] WhiteSpaceChars = new char[] { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x05, 
            (char)0x06, (char)0x07, (char)0x08, (char)0x09, (char)0x0a, (char)0x0b, (char)0x0c, (char)0x0d, (char)0x0e, (char)0x0f, 
            (char)0x10, (char)0x11, (char)0x12, (char)0x13, (char)0x14, (char)0x15, (char)0x16, (char)0x17, (char)0x18, (char)0x19, (char)0x20,
            (char)0x1a, (char)0x1b, (char)0x1c, (char)0x1d, (char)0x1e, (char)0x1f, (char)0x7f, (char)0x85, (char)0x2028, (char)0x2029 
            ,(char)0x0027, (char)0x0022, (char)0x005C, (char)0x0000, (char)0x0007, (char)0x0008, (char)0x000C, (char)0x000A, (char)0x000D , (char)0x0009, (char)0x000B  

    };


    /// 
    /// Descrioption:
    /// 清空空白字符
    /// Author     : 付義方
    /// Create Date: 2014-03-06
    /// 
    ///
    /// 
    public static string NotNullOrBlank(this string value)
    {

        string result = string.Empty;
        if (!string.IsNullOrEmpty(value))
        {
            result = value.Trim(WhiteSpaceChars);

        }

        if (!string.IsNullOrEmpty(result))
        {
            result = StringToPattern(result);
        }

        return result;
    }


    /// 
    /// Descrioption:
    /// 替換制表符
    /// Author     : 付義方
    /// Create Date: 2014-03-06
    /// 
    /// 
    ///待過濾的內容
    /// 返回過濾完成的內容
    public static string StringToPattern(string content)
    {
        if (content.Trim().Equals(""))
        {
            return string.Empty;
        }
        else
        {
            for (int i = 0; i < WhiteSpaceChars.Length; i++)
            {
                content = content.Replace(WhiteSpaceChars[i].ToString(), "");
            }
        }

        return content;
    }


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved