用text转换html简单代码、截取

后台代码:

        ///


        /// 将text格式简单的转换成HTML格式保存
        ///

        /// 进行转换的字符串
        /// 转换后的字符串
        public static string ConverToHtml(string str)
        {
            string tem = str;
            tem.Replace(" ", " ");
            tem.Replace("<", "<");
            tem.Replace(">", ">");
            tem .Replace ("\r","
");
            tem.Replace("&", "&");
            tem .Replace ("/",""");
            return tem;
        }

这方法很原始,如果行,可以考虑用文本插件。

 

简单的对文章截取:

        ///


        /// 字符段的截取
        ///

        /// 字符串
        /// 截取长度
        /// 截取后的字符串
        public static string Cut(string str, int length)
        {
            if (str.Length > length)
            {
                string stem=null;
                for (int i = 0; i < length; i++)
                {
                    stem += str[i];
                }
                return stem+"……";
            }
            else
            {
                return str;
            }
        }

 

 

 

你可能感兴趣的:(C#,asp.net)