开发者

the meaning of Contains(@"""")) in c#

A string strChkQo开发者_如何学Pythonutes is

IF(H15:H119=\"y\",IF(G15:G119=\"y\",1,0)

The following value is true(c#).

strChkQoutes.Contains(@"""")

I don't understand it's meaning. If I want to convert it to java, the string strChkQoutes is

IF(H15:H119="y",IF(G15:G119="y",1,0)

the following value is false(java).

strChkQoutes.contains("\"\"")   

what is the difference of the contains function in .net and in java?


The difference here doesn't lie in the methods, but the strings you're passing to the methods.

In C# verbatim string literals, @"""" really means one double quote character. The first inner " escapes the second inner ", since you can't use backslashes for escaping. Reference.

If you didn't use a verbatim string literal, the C# call would look like this:

strChkQuotes.Contains("\"")

Which is different from your Java string, which contains two escaped double quotes in a row and so causes contains() to return false.


@ is a C# String literal that java does not have. In Java you'd have to escape your string: .contains("\""). See here for how @-literals are resolved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜