C#定位字元過濾處理方法

來源:互聯網
上載者:User
C#定位字元過濾處理方法,動態替換字串裡面的定位字元。

/// <summary>/// 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/// <summary>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  };  /// <summary>/// Descrioption:/// 清空空白字元/// Author     : 付義方/// Create Date: 2014-03-06/// </summary>///<param name="value">/// <returns></returns>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;}  /// <summary>/// Descrioption:/// 替換定位字元/// Author     : 付義方/// Create Date: 2014-03-06/// </summary>/// </summary>///<param name="content">待過濾的內容/// <returns>返回過濾完成的內容</returns>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;}</summary>

以上就是C#定位字元過濾處理方法的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.