以'开头的字符串不会连接 [英] String starting with ' won't concatenate

查看:55
本文介绍了以'开头的字符串不会连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些错误处理代码:


catch(System.Xml.XmlException e)

{

Console.WriteLine( 错误输入+ e.SourceUri +":" + e.Message);

返回;

}


输出:


''是一个意外的令牌。预期的令牌是''>''。第17行,第50位。


删除e.Message之前的字符串中的所有内容。我怀疑这是因为Message属性以''开头。有解决方法吗?


Gustaf

解决方案

Gustaf写道:


一些错误处理代码:


catch(System.Xml.XmlException e)

{

Console.WriteLine("" + e.SourceUri +":" + e.Message);

return;

}


输出:


''是一个意外的令牌。预期的令牌是''>''。第17行,第50位。


删除e.Message之前的字符串中的所有内容。我怀疑

这是因为Message属性以''开头。这是否有一个

的解决方法?



e.SourceUri的价值是什么,e.Message的价值是多少?你怀疑b $ b怀疑是不正确的。例如:


string uri =" http://www.uri.com/" ;;

string message ="''是一个意外的令牌。预期的令牌是''>''。

第17行,第50位。;

Console.WriteLine("" + uri +" ;:" + message);


输出:


http://www.uri.com/:''是一个意想不到的标记。预期的

令牌是''>''。第17行,第50位。

-

Tom Porterfield


Tom Porterfield写道:
< blockquote class =post_quotes>
e.SourceUri的价值是什么,e.Message的价值是多少?



e.SourceUri的值是file:/// d:/test/po.xsd"。 e.Message的值是以''开头的字符串。所以我期望的完整输出是:


文件错误:/// d:/test/po.xsd:''是一个意外的令牌。

第17行,第50位。


一旦我使用e.Message并且它有此特定消息(以''开头),它将删除e.Message部分之前的所有内容。


如果我在* e.Message之后添加一个字符串*,它会保留在那里。此外,如果我让它显示另一个错误(不是以''开头),它可以工作:


文件错误:/// d:/test/po.xsd:' 'xs:element''开始标记

第17行与''xs:element_''的结束标记不匹配。第17行,

位置52.


所以我仍然相信它是'e.Message开头'''导致它。


Gustaf


7月26日下午1:33,Gustaf< gust ... @ algonet .sewrote:


< snip>


所以我仍然相信它是'' e.Message的开头,它正在引起它。



您能否制作一个简短但完整的程序来演示

问题?

参见 http://pobox.com/~skeet/csharp/complete.html 更多详情

关于我的意思。


Jon


Some error handling code:

catch (System.Xml.XmlException e)
{
Console.WriteLine("Error in " + e.SourceUri + ": " + e.Message);
return;
}

The output:

'' is an unexpected token. The expected token is ''>''. Line 17, position 50.

Everything in the string before e.Message is deleted. I suspect that this is because the Message property starts with ''. Is there a workaround for this?

Gustaf

解决方案

Gustaf wrote:

Some error handling code:

catch (System.Xml.XmlException e)
{
Console.WriteLine("Error in " + e.SourceUri + ": " + e.Message);
return;
}

The output:

'' is an unexpected token. The expected token is ''>''. Line 17, position 50.

Everything in the string before e.Message is deleted. I suspect that
this is because the Message property starts with ''. Is there a
workaround for this?

What is the value of e.SourceUri, what is the value of e.Message? Your
suspicion is incorrect. Ex:

string uri = "http://www.uri.com/";
string message = "'' is an unexpected token. The expected token is ''>''.
Line 17, position 50.";
Console.WriteLine("Error in " + uri + ": " + message);

Outputs:

Error in http://www.uri.com/: '' is an unexpected token. The expected
token is ''>''. Line 17, position 50.
--
Tom Porterfield


Tom Porterfield wrote:

What is the value of e.SourceUri, what is the value of e.Message?

The value of e.SourceUri is "file:///d:/test/po.xsd". The value of e.Message is the string starting with ''. So the full output I expect is:

Error in file:///d:/test/po.xsd: '' is an unexpected token.
Line 17, position 50.

As soon as I use e.Message and it has this particular message (starting with ''), it removes everything before the e.Message part.

If I add a string *after* e.Message, it stays there. Also, if I make it show another error (not starting with ''), it works:

Error in file:///d:/test/po.xsd: The ''xs:element'' start tag on
line 17 does not match the end tag of ''xs:element_''. Line 17,
position 52.

So I''m still convinced it''s the '' in the beginning of e.Message that''s causing it.

Gustaf


On Jul 26, 1:33 pm, Gustaf <gust...@algonet.sewrote:

<snip>

So I''m still convinced it''s the '' in the beginning of e.Message that''s causing it.

Can you produce a short but complete program which demonstrates the
problem?
See http://pobox.com/~skeet/csharp/complete.html for more details
about what I mean.

Jon


这篇关于以'开头的字符串不会连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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