如何字符串生成器转换成字符串不转义序列在转换后的字符串 [英] How to converting string builder to string without escape sequence in the converted string
问题描述
我写了一些XML数据到的StringWriter。我想通过在StringWriter的到数据库中的值,但是当我把它转换为字符串,如
I am writing some XML data to the stringwriter. I want to pass the values in the stringwriter to the database but when I convert it to a string like
StringWriter.GetStringBuilder()。toString()方法是将所有的(双引号)\\
StringWriter.GetStringBuilder().ToString() it is converting all the " (double quotes) to \"
所以,当我传递到数据库的参数,当我尝试使用的OpenXML它抛出一个错误读取数据。
So when I pass that to database as parameter and when I try to read the data using openXML it's throwing an error.
有任何工作围绕这个?
我使用ASP.NET 2.0
SQL Server 2005中
I am using ASP.NET 2.0
SQl server 2005
谢谢!
推荐答案
我强烈怀疑,你看调试器。这将显示逃出,但行情不会实际在字符串中,如果他们不应该。
I strongly suspect that you're looking at the debugger. That will show the escaped form, but the quotes won't actually be in the string if they shouldn't be.
我建议你以某种方式登录字符串 - 然后你会看到真实的数据,我的猜测是,它不包含反斜线 - 假设你没有任何书面反斜杠到的StringWriter
开始。你是如何将数据写入到的StringWriter
?有没有可能是你的问题进一步上行? (如果你正在写XML的手动的,我强烈建议你使用XML API来代替。它更不容易出错。)
I suggest you log the string somehow - then you'll see the real data, and my guess is that it won't contain the backslashes - assuming you haven't written any backslashes to the StringWriter
to start with. How are you writing the data to the StringWriter
? Is it possible that your problems are further upstream? (If you're writing the XML manually, I'd strongly recommend that you use an XML API instead. It's much less error-prone.)
什么错误你得到试图读取XML回来的时候?是什么样子的数据库?
What error are you getting when trying to read the XML back? What does it look like in the database?
我可以pretty多保证该问题将不会在的StringWriter
或的StringBuilder
- 他们不执行任何转义。
I can pretty much guarantee that the problem won't be in StringWriter
or StringBuilder
- they don't perform any escaping.
在另一方面,没有任何理由,为什么你叫 GetStringBuilder()的ToString()
,而不是仅仅的ToString()
?
On another note, is there any reason why you're calling GetStringBuilder().ToString()
instead of just ToString()
?
这篇关于如何字符串生成器转换成字符串不转义序列在转换后的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!