恒定错误中的新行

编程入门 行业动态 更新时间:2024-10-24 23:23:57
本文介绍了恒定错误中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个 c# 代码,我在其中从数据库中获取值并使用它.我面临的问题如下.

I am writing a c# code in which i am fetching values from the database and using it. The problem i am facing is as below.

如果我从数据库中获取的值是:

If my fetched value from the database is :

string cat1 = "sotheby's";

现在在使用这只猫时,我想在单引号之前插入一个转义字符,为此我编写了以下代码:

now while using this cat i want to insert an escape character before single quote, to achieve this i have written the below code:

string cat1 = "sotheby's"; if (cat1.Contains("'")) { var indexofquote = cat1.IndexOf("'"); cat1.Insert(indexofquote-1,""); var cat2 = cat1; }

插入行中的错误上升,反斜杠(转义字符).错误是常量中的新行.请帮助我如何更正此错误.

The error rises in insert line, the backslash(escape character). The error is New Line in Constant. Please help me how to correct this error.

推荐答案

你不能只用 C# 代码编写 "".这将产生常量中的新行"错误,因为它转义"了第二个引号,因此它不计算在内.并且字符串没有关闭.

You can't just write "" in C# code. That will produce the "New Line in Constant" error because it 'escapes' the second quote so that it doesn't count. And the string isn't closed.

使用 "\" (自行转义 )或使用 @""(逐字字符串).

Use either "\" (escaping the with itself) or use @"" (a verbatim string).

更多推荐

恒定错误中的新行

本文发布于:2023-11-04 12:19:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!