首页 > 后端开发 > C#.Net教程 > C#制表符过滤处理方法

C#制表符过滤处理方法

黄舟
发布: 2016-12-27 14:11:27
原创
1682 人浏览过

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#制表符过滤处理方法的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板