pas 文件中字符串的格式
当字符串跨越多行时,有没有一种好的方法可以将字符串分配给变量?
做的原因是我有一些大的 SQL 语句(我想要在 pas 中),但是像这样
var
sql : string;
begin
sql := 'SELECT * ' +
'FROM foo ' +
'WHERE `this`=0';
复制并粘贴到终端/另一个程序中很烦人,因为我必须删除 ' 和 ' + 等。
这样 一种类似于...的方法
var
sql : string;
begin
sql := ""SELECT *
FROM foo
WHERE `this`=0"";
,可以用新行分配文本/字符串块,而无需将其连接起来。
Is there a nice way to assign a string to a variable when it spans many lines?
The reason for this is I have some large SQL statements (which I want in the pas) but it's annoying like this
var
sql : string;
begin
sql := 'SELECT * ' +
'FROM foo ' +
'WHERE `this`=0';
That is annoying to copy and paste into terminal / another program because I have to remove the ' and ' + etc.
Is there a way to so something like...
var
sql : string;
begin
sql := ""SELECT *
FROM foo
WHERE `this`=0"";
So some way to assign a block of text/string with new lines without having to concat it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我所知(至少不是开箱即用的)。无论如何,您可能想看看这个:
如何在不引用每一行的情况下分配多行字符串值?
Not that I know of (at least not out of the box). Anyway, you might want to take a look at this:
How to assign a multiline string value without quoting each line?
您可以将 SQL 保留在具有 TStrings 属性(如 TSQLQuery)的组件中,但我对较长/复杂语句的解决方案是保留“示例”副本作为源代码注释,它具有实际参数以使测试更容易,并保留两者版本同步。
You could keep the SQL in a component which has a TStrings property like TSQLQuery, but my solution for longer / complex statements is to keep an 'example' copy as a source code comment, which has actual parameters to make tests easier, and keep both version in sync.
如果您喜欢 C# 的做法(就像我一样),那么请不要忘记为此 QC 报告投票:
http://qc.embarcadero.com/wc/qcmain.aspx?d=2012
它建议使您的示例如下所示:
If you like the way C# does it (like I do), then don't forget to vote for this QC report:
http://qc.embarcadero.com/wc/qcmain.aspx?d=2012
It suggests to make your example look like this:
如果你在Delphi中安装GExperts,IDE会在按下后自动插入一个
'+
>输入<如果你在一个字符串内并且还没有关闭它。下载链接:http://www.gexperts.org/download.html
If you install GExperts in Delphi, the IDE will automatically insert a
'+
after pressing >enter< if you're inside a string and haven't closed it yet.Download link: http://www.gexperts.org/download.html
由于在 SQL 中无法以这种方式表达字符串,因此我通常使用 Delphi IDE 中提供的 RegEx 搜索和替换来按照所需的方式格式化字符串。
这会将任何行替换为用引号引起来的行,后跟
+ sLineBreak +
然后我只需整理最后一行:
当然,可以对任何前面或后面的文本执行相同的操作,例如
qry.SQL.Add('\0');
As there is no way of expressing strings in this way in SQL, I normally use the RegEx search and replace available in the Delphi IDE to format strings in the required way.
This replaces any line with the line enclosed in quotes, followed by
+ sLineBreak +
I then just tidy up the last line:
Of course the same can be done with any preceding or trailing text, such as
qry.SQL.Add('\0');
你的问题是:
答案是否定的。
Your question is:
The answer is no.