逃离逐字字符串 [英] Escaping verbatim string literals

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

问题描述

我有以下字符串,将不能编译:

I have the following string which won't compile:

String formLookupPull = @"SELECT value1, '"+tableName+"', '"+columnName+"' FROM lkpLookups WHERE ""table"" = '" + tableName + "' and ""field"" = '" + columnName + "';";

有问题的部分是:

""table"" =

""field"" = 

编译器让所有的转义序列混合起来。任何人都可以看到什么了?

The compiler is getting all mixed up on the escape sequence. Can anyone see what's wrong?

推荐答案

现在的问题是,并非所有的你是串联两个字符串的逐字字符串,只有串联的第一部分。

The problem is that not all the strings you are concatenating are verbatim string literals, only the first portion of the concatenation is.

在换句话说,

@"SELECT value1, '"

是唯一的逐字的文字在整个语句生成最终的字符串。

is the only verbatim literal in the entire statement to build the final string.

您需要在您的字符串的其余部分的前面加@,使他们都一字不差。

You would need to add @ in front of the rest of your strings to make them all verbatim.

这将使它看起来像:

String formLookupPull = @"SELECT value1, '"+tableName+ @"', '"+columnName+ @"' FROM lkpLookups WHERE ""table"" = '" + tableName + @"' and ""field"" = '" + columnName + @"';";

这篇关于逃离逐字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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