如题C#  一串字符 写入 MSSQL表(text型)时 换行 自动变成了 \r\n  如果在保存时 删除掉这个 \r\n
好象varchar型的不会这样的

解决方案 »

  1.   

    LZ想问什么?  删除\r\n??        /// <summary>
            /// 删除字符串尾部的回车/换行/空格
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string RTrim(string str)
            {
                for (int i = str.Length; i >= 0; i--)
                {
                    if (str[i].Equals(" ") || str[i].Equals("\r") || str[i].Equals("\n"))
                    {
                        str.Remove(i, 1);
                    }
                }
                return str;
            }
            /// <summary>
            /// 清除给定字符串中的回车及换行符
            /// </summary>
            /// <param name="str">要清除的字符串</param>
            /// <returns>清除后返回的字符串</returns>
            public static string ClearBR(string str)
            {
                Regex r = null;
                Match m = null;            r = new Regex(@"(\r\n)", RegexOptions.IgnoreCase);
                for (m = r.Match(str); m.Success; m = m.NextMatch())
                {
                    str = str.Replace(m.Groups[0].ToString(), "");
                }
                return str;
            }
      

  2.   

    直接
    test= test.Replace("\r\n","");
    手工输入的\r\n.在string里面是\\r\\n
      

  3.   

    test= test.Replace("\r\n",string.Empty);