日期:2014-05-18  浏览次数:20434 次

求高手指教一下这段功能的每一句代码什么意思。新手
求高手指教一下这段功能的每一句代码什么意思。最好在每一句后面加上注释


C# code

#region 用于处理多行文本的公共方法
    /// <summary>
    /// 返回多行输入的字符串并删除超过限定字数的字符同时进行Html编码
    /// </summary>
    /// <param name="instr">要过滤的字符串</param>
    /// <param name="WordCount">保留的字数</param>
    /// <param name="NewLine">设置一个值,该值表示是否显示换行符。</param>
    /// <returns></returns>
    private static string MultiLineStrConv(string instr, int WordCount, bool NewLine)
    {
        instr = instr.Trim();
        objregex = new Regex(" +");
        instr = objregex.Replace(instr, " ");
        instr = instr.Replace(Environment.NewLine + " ", Environment.NewLine);
        instr = instr.Replace(" " + Environment.NewLine, Environment.NewLine);
        instr = instr.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
        instr = HttpContext.Current.Server.HtmlEncode(instr);
        instr = instr.Replace("'", "''");
        if (NewLine)
        {
            instr = instr.Replace(Environment.NewLine, "<br />" + Environment.NewLine);
        }
        if (WordCount > 0 && instr.Length > WordCount)
        {
            instr = instr.Substring(0, WordCount);
        }
        return instr;
    }
    #endregion




------解决方案--------------------
就是对指定长度字符串进行html编码啊