字符串中不需要的转义码... [英] Unwanted Escape Codes In String...

查看:98
本文介绍了字符串中不需要的转义码...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我已经构建了一个XMLDocument对象实例,当我检查InnerXml属性时,我得到以下字符串




<?xml version = \" 1.0 \"?>< ROOT>< UserData UserID = \" 2282 \">< Tag1

QID = \" 55111 \">< Tag2 AID = \" 5511101 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55112 \">< Tag2

AID = \" 5511217 \">< / Tag2>< / Tag1>< Tag1 QID = \" 5512282 \">< Tag2

AID = \" 551228206 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55114 \">< Tag2

AID = \" 5511406 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55115 \">< Tag2

AID = \" 5511505 \">< / Tag2>< / Tag1>< / UserData> < / ROOT>


请注意在双引号都被转义 - 也就是说它们显示为


\"


vs.

"


我想转换或转换将此字符串转换为一个字符串,其中转义符号是转换的转换符号。这将生成一个字符串,

将如下所示:


<?xml version =" 1.0"?>< ROOT>< ; UserData UserID =" 2282">< Tag1 QID =" 55111">< Tag2

AID =" 5511101">< / Tag2>< / Tag1> < Tag1 QID =" 55112">< Tag2

AID =" 5511217">< / Tag2>< / Tag1>< Tag1 QID =" 5512282"> ;< Tag2

AID =" 551228206">< / Tag2>< / Tag1>< Tag1 QID =" 55114">< Tag2

AID =" 5511406">< / Tag2>< / Tag1>< Tag1 QID =" 55115">< Tag2

AID =" 5511505"> < / Tag2>< / Tag1>< / UserData>< / ROOT>


我不想使用搜索/替换算法,因为我不能完全

确保除了\之外不会有转义序列在字符串中。我实际上正在寻找一种能够转变的解决方案。 \到 (因为我需要b $ b b),但也可以将\ n转换为ASCII 10而将\ r转换为ASCII 13.

换句话说,我想转换转义编码的字符串为

标准ASCII字符串。


此外,为什么XMLDocument的InnerXml返回转义编码

字符串而不是直线字符串(未编码)字符串?有没有办法让

InnerXml返回直?串?我计划将XML字符串作为一个参数传递给Sql存储过程

;因此,编码的字符串确实没有工作 - 我必须使用未编码的版本。当然其他人有
遇到这个问题 - 我找不到单一的解决方案而且我花了几个小时搜索MSDN和Google!例如,我读了一些建议使用ActiveXMessageFormatter的其他

线程,但不是其中之一

实际上解释了如何做 - 而伪代码只能是如此有用。 ..


提前感谢您的帮助。我将确认是否有任何

建议工作。


问候,

史蒂夫

解决方案

它是C#转义字符,即\,以及C和C ++。

你做的不必用anythng替换它。保持原样。

只需按原样将其传递给存储过程,它就能正常工作。


Steve Litvack <我们************ @ yahoo.com>在消息中写道

新闻:RD ******************** @ twister.austin.rr.com。 ..

你好,

我已经构建了一个XMLDocument对象实例,当我检查InnerXml属性时,我得到以下字符串

/><?xml version = \" 1.0 \"?>< ROOT>< UserData UserID = \" 2282 \">< Tag1
QID = \\ \\55111 \">< Tag2 AID = \" 5511101 \">< / Tag2>< / Tag1>< Tag1
QID = \" 55112 \">< Tag2 AID = \" 5511217 \">< / Tag2>< / Tag1>< Tag1 QID = \" 5512282 \">< Tag2
AID = \" 551228206 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55114 \">< Tag2 AID = \" 5511406 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55115 \">< Tag2
AID = \\ \\5511505 \">< / Tag2>< / Tag1>< / UserData>< / ROOT>

请注意双重现实测试都被逃脱了 - 也就是说它们显示为






"

我想改造或转换将此字符串转换为
中的字符串,转义字符将被转换。这将产生一个如下所示的字符串:

<?xml version =" 1.0"?>< ROOT>< UserData UserID =" 2282" ><< Tag1 QID =" 55111">< Tag2
AID =" 5511101">< / Tag2>< / Tag1>< Tag1 QID =" 55112">< ; Tag2
AID =" 5511217">< / Tag2>< / Tag1>< Tag1 QID =" 5512282">< Tag2
AID =" 551228206"> < / Tag2>< / Tag1>< Tag1 QID =" 55114">< Tag2
AID =" 5511406">< / Tag2>< / Tag1>< Tag1 QID =" 55115">< Tag2
AID =" 5511505">< / Tag2>< / Tag1>< / UserData>< / ROOT>

我不想使用搜索/替换算法,因为我不能完全确定除了\"之外不会有
。在字符串中。
我实际上正在寻找一种能够转变的解决方案。 \到 (因为我需要)但也可以将\ n转换为ASCII 10和\ r转换为ASCII
13.换句话说,我想将转义编码的字符串转换为
标准ASCII字符串。

此外,为什么XMLDocument的InnerXml返回一个转义编码的字符串而不是直字符串。 (未编码)字符串?有没有办法让
的InnerXml返回直?串?我计划将XML字符串作为参数传递给Sql存储过程;因此,编码的字符串不起作用 - 我必须使用未编码的版本。当然其他人已经遇到了这个问题 - 我找不到单一的解决方案而且我花了好几个小时搜索MSDN和谷歌!例如,我读了一些建议使用ActiveXMessageFormatter的其他线程,但其中没有一个
实际上解释了如何做 - 而伪代码只能是如此有用......

提前感谢您的帮助。我将确认是否有任何建议。

问候,
史蒂夫


它是C#转义字符,即\,以及C和C ++。

您不必将其替换为anythng。保持原样。

只需按原样将其传递给存储过程,它就能正常工作。


Steve Litvack <我们************ @ yahoo.com>在消息中写道

新闻:RD ******************** @ twister.austin.rr.com。 ..

你好,

我已经构建了一个XMLDocument对象实例,当我检查InnerXml属性时,我得到以下字符串

/><?xml version = \" 1.0 \"?>< ROOT>< UserData UserID = \" 2282 \">< Tag1
QID = \\ \\55111 \">< Tag2 AID = \" 5511101 \">< / Tag2>< / Tag1>< Tag1
QID = \" 55112 \">< Tag2 AID = \" 5511217 \">< / Tag2>< / Tag1>< Tag1 QID = \" 5512282 \">< Tag2
AID = \" 551228206 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55114 \">< Tag2 AID = \" 5511406 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55115 \">< Tag2
AID = \\ \\5511505 \">< / Tag2>< / Tag1>< / UserData>< / ROOT>

请注意双重现实测试都被逃脱了 - 也就是说它们显示为






"

我想改造或转换将此字符串转换为
中的字符串,转义字符将被转换。这将产生一个如下所示的字符串:

<?xml version =" 1.0"?>< ROOT>< UserData UserID =" 2282" ><< Tag1 QID =" 55111">< Tag2
AID =" 5511101">< / Tag2>< / Tag1>< Tag1 QID =" 55112">< ; Tag2
AID =" 5511217">< / Tag2>< / Tag1>< Tag1 QID =" 5512282">< Tag2
AID =" 551228206"> < / Tag2>< / Tag1>< Tag1 QID =" 55114">< Tag2
AID =" 5511406">< / Tag2>< / Tag1>< Tag1 QID =" 55115">< Tag2
AID =" 5511505">< / Tag2>< / Tag1>< / UserData>< / ROOT>

我不想使用搜索/替换算法,因为我不能完全确定除了\"之外不会有
。在字符串中。
我实际上正在寻找一种能够转变的解决方案。 \到 (因为我需要)但也可以将\ n转换为ASCII 10和\ r转换为ASCII
13.换句话说,我想将转义编码的字符串转换为
标准ASCII字符串。

此外,为什么XMLDocument的InnerXml返回一个转义编码的字符串而不是直字符串。 (未编码)字符串?有没有办法让
的InnerXml返回直?串?我计划将XML字符串作为参数传递给Sql存储过程;因此,编码的字符串不起作用 - 我必须使用未编码的版本。当然其他人已经遇到了这个问题 - 我找不到单一的解决方案而且我花了好几个小时搜索MSDN和谷歌!例如,我读了一些建议使用ActiveXMessageFormatter的其他线程,但其中没有一个
实际上解释了如何做 - 而伪代码只能是如此有用......

提前感谢您的帮助。我将确认是否有任何建议。

问候,
史蒂夫


您可以发布您的SP代码以及创建SP参数的代码吗?


" Steve Litvack" <我们************ @ yahoo.com>在消息中写道

新闻:Ps ******************** @ twister.austin.rr.com。 ..

否 - 它不起作用。这就是我发布消息的原因。
SQL Server报告:

服务器:消息6603,级别16,状态1,过程sp_xml_preparedocument,
第27行

XML解析错误:预期字符串文字,但没有找到开头引用的字符。

如果有人对如何生成纯字符有任何想法我要求提供ASCII XML文本,请告诉我。

谢谢,
- 史蒂夫

dd <所以***** @ somewhere.com>在消息中写道
新闻:美国******************** @ news20.bellglobal.com。 ..

它是C#转义字符,即\,以及C和C ++。
您不必用anythng替换它。离开它。
只要将它原样传递给你的存储过程,它就可以正常工作。

Steve Litvack <我们************ @ yahoo.com>在消息中写道
新闻:RD ******************** @ twister.austin.rr.com。 ..

你好,

我已经构建了一个XMLDocument对象实例,当我检查InnerXml属性时,我得到以下字符串:

< ?xml version = \" 1.0 \"?>< ROOT>< UserData UserID = \" 2282 \">< Tag1
QID = \" 55111 \">< Tag2 AID = \" 5511101 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55112 \">< Tag2

AID = \" 5511217 \">< / Tag2>< / Tag1>< Tag1 QID = \" 5512282 \">< Tag2
AID = \" 551228206 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55114 \">< Tag2 AID = \" 5511406 \">< / Tag2>< / Tag1>< Tag1 QID = \" 55115 \">< Tag2
AID = \\ \\5511505 \">< / Tag2>< / Tag1>< / UserData>< / ROOT>

Notic e双引号都被转义 - 即它们显示为

\"

对比

"

我想转变或转换将此字符串转换为


中的字符串,其中

转义字符被转换。这将产生如下所示的字符串


<?xml version =" 1.0"?>< ROOT>< UserData UserID =" 2282" ><< Tag1 QID =" 55111">< Tag2 AID =" 5511101">< / Tag2>< / Tag1>< Tag1 QID =" 55112">< Tag2
AID =" 5511217">< / Tag2>< / Tag1>< Tag1 QID =" 5512282">< Tag2
AID =" 551228206">< / Tag2> ;< / Tag1>< Tag1 QID =" 55114">< Tag2
AID =" 5511406">< / Tag2>< / Tag1>< Tag1 QID =" 55115" ;><< Tag2
AID =" 5511505">< / Tag2>< / Tag1>< / UserData>< / ROOT>

我不想要使用搜索/替换算法,因为我不能


完全

确保除了\之外不会有转义序列在字符串中。

我实际上正在寻找一种能够转换的解决方案。 \到 (作为
我需要)但也可以将\ n转换为ASCII 10和\ r转换为
ASCII

13. < blockquote class =post_quotes>换句话说,我想将转义编码的字符串转换为
标准ASCII字符串。

此外,为什么XMLDocument的InnerXml返回转义编码的字符串而不是直字符串(未编码)字符串?有没有办法


得到

InnerXml来返回直&串?我计划将XML



字符串作为参数传递给Sql存储过程;因此,编码的字符串不起作用 - 我必须使用未编码的版本。当然其他人已经遇到了这个问题 - 我找不到单一的解决方案和



我花了几个小时搜索MSDN和谷歌!例如,我读了一些建议使用ActiveXMessageFormatter的其他线程,但不是
中的一个,它们实际上解释了如何做 - 而伪代码只能是这样的
有用...
提前感谢您的帮助。我将确认是否有任何建议。

问候,
史蒂夫




Hello,

I have built an XMLDocument object instance and I get the following string
when I examine the InnerXml property:

<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2
AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>

Notice that the double quotes are all escaped--that is they appear as

\"

versus

"

I would like to "transform" or "convert" this string into a string in which
the escape characters are "converted". This would generate a string that
would appear like this:

<?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2
AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
AID="5511505"></Tag2></Tag1></UserData></ROOT>

I do not want to use a search/replace algorithm because I cannot be entirely
sure that there will not be escape sequences other than \" in the string. I
am actually seeking a solution that would "transform" the \" to " (as I
require) but also one that would convert \n to ASCII 10 and \r to ASCII 13.
In other words, I would like to convert the escape-encoded string to a
standard ASCII string.

Moreover, why does the XMLDocument''s InnerXml return an escape-encoded
string instead of a "straight" (unencoded) string? Is there a way to get the
InnerXml to return the "straight" string? I plan to pass the XML string as
an argument to a Sql stored procedure; therefore, the encoded string does
not work--I must use the unencoded version. Certainly others have
encountered this problem--I just could not find a single solution and I
spend hours searching MSDN and Google! For example, I read some other
threads that suggest using ActiveXMessageFormatter, but not one of them
actually explained how to do it--and pseudocode can only be so useful...

Thank you in advance for any assistance. I will confirm whether any
suggestions work.

Regards,
Steve


解决方案

It is the C# escape character, i.e. "\", as well as C and C++.
You do not have to replace it with anythng. Just leave it.
Just pass it to your stored procedure as is, it will work OK.

"Steve Litvack" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..

Hello,

I have built an XMLDocument object instance and I get the following string
when I examine the InnerXml property:

<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2 AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>

Notice that the double quotes are all escaped--that is they appear as

\"

versus

"

I would like to "transform" or "convert" this string into a string in which the escape characters are "converted". This would generate a string that
would appear like this:

<?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2
AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
AID="5511505"></Tag2></Tag1></UserData></ROOT>

I do not want to use a search/replace algorithm because I cannot be entirely sure that there will not be escape sequences other than \" in the string. I am actually seeking a solution that would "transform" the \" to " (as I
require) but also one that would convert \n to ASCII 10 and \r to ASCII 13. In other words, I would like to convert the escape-encoded string to a
standard ASCII string.

Moreover, why does the XMLDocument''s InnerXml return an escape-encoded
string instead of a "straight" (unencoded) string? Is there a way to get the InnerXml to return the "straight" string? I plan to pass the XML string as
an argument to a Sql stored procedure; therefore, the encoded string does
not work--I must use the unencoded version. Certainly others have
encountered this problem--I just could not find a single solution and I
spend hours searching MSDN and Google! For example, I read some other
threads that suggest using ActiveXMessageFormatter, but not one of them
actually explained how to do it--and pseudocode can only be so useful...

Thank you in advance for any assistance. I will confirm whether any
suggestions work.

Regards,
Steve



It is the C# escape character, i.e. "\", as well as C and C++.
You do not have to replace it with anythng. Just leave it.
Just pass it to your stored procedure as is, it will work OK.

"Steve Litvack" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..

Hello,

I have built an XMLDocument object instance and I get the following string
when I examine the InnerXml property:

<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2 AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>

Notice that the double quotes are all escaped--that is they appear as

\"

versus

"

I would like to "transform" or "convert" this string into a string in which the escape characters are "converted". This would generate a string that
would appear like this:

<?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2
AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
AID="5511505"></Tag2></Tag1></UserData></ROOT>

I do not want to use a search/replace algorithm because I cannot be entirely sure that there will not be escape sequences other than \" in the string. I am actually seeking a solution that would "transform" the \" to " (as I
require) but also one that would convert \n to ASCII 10 and \r to ASCII 13. In other words, I would like to convert the escape-encoded string to a
standard ASCII string.

Moreover, why does the XMLDocument''s InnerXml return an escape-encoded
string instead of a "straight" (unencoded) string? Is there a way to get the InnerXml to return the "straight" string? I plan to pass the XML string as
an argument to a Sql stored procedure; therefore, the encoded string does
not work--I must use the unencoded version. Certainly others have
encountered this problem--I just could not find a single solution and I
spend hours searching MSDN and Google! For example, I read some other
threads that suggest using ActiveXMessageFormatter, but not one of them
actually explained how to do it--and pseudocode can only be so useful...

Thank you in advance for any assistance. I will confirm whether any
suggestions work.

Regards,
Steve



Can you post your SP code as well as the code that creates SP paramaters?

"Steve Litvack" <us************@yahoo.com> wrote in message
news:Ps********************@twister.austin.rr.com. ..

No--it does not work. That is why I posted the message.

SQL Server reports:

Server: Msg 6603, Level 16, State 1, Procedure sp_xml_preparedocument, Line 27

XML parsing error: A string literal was expected, but no opening quote
character was found.
If anyone has any ideas on how to generate the "pure" ASCII XML text I
requested, please let me know.

Thanks,
-- Steve

"dd" <so*****@somewhere.com> wrote in message
news:uS********************@news20.bellglobal.com. ..

It is the C# escape character, i.e. "\", as well as C and C++.
You do not have to replace it with anythng. Just leave it.
Just pass it to your stored procedure as is, it will work OK.

"Steve Litvack" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..

Hello,

I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property:

<?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1
QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2

AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2
AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2
AID=\"5511406\"></Tag2></Tag1><Tag1 QID=\"55115\"><Tag2
AID=\"5511505\"></Tag2></Tag1></UserData></ROOT>

Notice that the double quotes are all escaped--that is they appear as

\"

versus

"

I would like to "transform" or "convert" this string into a string in


which

the escape characters are "converted". This would generate a string that would appear like this:

<?xml version="1.0"?><ROOT><UserData UserID="2282"><Tag1 QID="55111"><Tag2 AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Tag2
AID="5511217"></Tag2></Tag1><Tag1 QID="5512282"><Tag2
AID="551228206"></Tag2></Tag1><Tag1 QID="55114"><Tag2
AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Tag2
AID="5511505"></Tag2></Tag1></UserData></ROOT>

I do not want to use a search/replace algorithm because I cannot be


entirely

sure that there will not be escape sequences other than \" in the string.

I

am actually seeking a solution that would "transform" the \" to " (as I require) but also one that would convert \n to ASCII 10 and \r to ASCII

13.

In other words, I would like to convert the escape-encoded string to a
standard ASCII string.

Moreover, why does the XMLDocument''s InnerXml return an escape-encoded
string instead of a "straight" (unencoded) string? Is there a way to

get the

InnerXml to return the "straight" string? I plan to pass the XML


string as an argument to a Sql stored procedure; therefore, the encoded string does not work--I must use the unencoded version. Certainly others have
encountered this problem--I just could not find a single solution and


I spend hours searching MSDN and Google! For example, I read some other
threads that suggest using ActiveXMessageFormatter, but not one of them actually explained how to do it--and pseudocode can only be so useful...
Thank you in advance for any assistance. I will confirm whether any
suggestions work.

Regards,
Steve





这篇关于字符串中不需要的转义码...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆