首页 新闻 会员 周边

linq to xml生成xml或者字符串 去掉回车或者换行

0
悬赏园豆:5 [已解决问题] 解决于 2013-06-08 12:51
            XDocument xd = new XDocument(
                new XDeclaration("1.0", "UTF-8", "yes"),
                new XElement("Command",
                    new XAttribute("name", "LOGIN_REQ"),
                    new XAttribute("sn", "1"),
                    new XAttribute("version", "1.0.0"),
                    new XElement("UserID", lg.userID),
                    new XElement("UserPwd", Convert.ToBase64String(Encoding.ASCII.GetBytes(lg.userPwd)))
                    ));
            return xd.ToString();

生成的xml 最后转换string

格式

我希望的是

中间不要那个回车还是换行符!

问题补充:

吃完饭突然想起了以前看的那个http协议的那个报文的思路 代码:

        private string cleanStringEmpty(string str)
        {
            if (!string.IsNullOrEmpty(str))
            {
                StringBuilder sb = new StringBuilder();
                string[] newStr = str.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < newStr.Length; i++)
                {
                    sb.Append(newStr[i].Trim());
                }
                return sb.ToString();
            }else
            {
                return null;
            }
        }

这样解决了!

但是我想linq to xml 里面应该有个属性设置可以 

s_p的主页 s_p | 初学一级 | 园豆:138
提问于:2013-06-07 11:58
< >
分享
最佳答案
0

把 \r,\n,\r\n 过滤掉

收获园豆:5
geass.. | 小虾三级 |园豆:1821 | 2013-06-07 13:20

解决了  谢谢 想linq to xml 里面应该有个属性设置可以 

s_p | 园豆:138 (初学一级) | 2013-06-07 13:23
其他回答(1)
0

求linq解决办法??

骑士归来 | 园豆:204 (菜鸟二级) | 2013-07-02 15:28

 我下面不是已经写了代码吗?我用的是字符分割 完成了 没有用linqto xml的解决办法

支持(0) 反对(0) s_p | 园豆:138 (初学一级) | 2013-07-03 18:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册