如何在 VS2015 中禁用自动字符串检测? [英] How can I disable automatic string detection in VS2015?

查看:23
本文介绍了如何在 VS2015 中禁用自动字符串检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 VB.NET,我的代码包含很多字符串,其中经常包含双引号.我的问题是,当我修复字符串以转义双引号(将字符串中的每个 '"' 替换为 '""')时,它会混淆正在进行的代码,暂时假设所有内容都是字符串(因为双引号不't match up) 并完全弄乱了其他字符串的格式.它假设后续字符串的开头是当前字符串的结尾,这会导致实际字符串被解释并格式化为代码,我必须返回并修复(因为它添加了实际上不应该存在的空格和其他格式字符).

I'm using VB.NET, and my code contains a lot of strings that very often have double quotes inside of them. My problem is that as I'm fixing the string to escape double quotes (replacing every '"' with '""' inside of the string) it messes with the proceeding code, temporarily assuming everything is a string (since the double quotes don't match up) and completely messing up the formatting of other strings. It assumes that the start of a following string is the end of the current string which causes the actual string to be interpreted and formatted as code, which I have to go back and fix (since it adds spaces and other formatting characters that shouldn't actually be there).

有什么办法可以禁用这种行为吗?我在 VS2013 中没有同样的问题.我一直在工具">选项">文本编辑器">基本"下查看,但找不到任何相关内容.

Is there any way to disable this behavior? I didn't have the same problem in VS2013. I've been looking under Tools > Options > Text Editor > Basic, but I couldn't find anything relevant.

附加信息:我可以修改单独文本文档中的字符串以转义所有双引号(这是我现在所采用的),但在 VS2013 中我可以轻松地将字符串直接复制/粘贴到我的代码中,而不会因为双引号的数量不均匀而暂时将它们解释为代码,从而弄乱正在处理的字符串.

Additional Information: I can just modify the strings in a separate text document to escape all of the double-quotes (which is what I've resorted to for now), but in VS2013 I could easily just copy/paste the strings directly into my code without it messing up proceeding strings by temporarily interpreting them as code due to the uneven count of double-quotes.

在字符串中手动添加双引号时,这种行为尤其成问题,因为如果您没有足够快地转义它们(或者在这样做时犯了一个简短的错字),您会遇到同样的问题.

This behavior is especially problematic when manually adding double-quotes within strings, because if you don't escape them quickly enough (or make a brief typo when doing so), you get the same issue.

您可能会注意到,对于其他语言,例如 C++,在一行中写入字符串(即使双引号数量奇数)不会影响后续行.假设有一些设置可以启用它,那么为 VB 提供相同的行为会很棒.

You might notice that for other languages, such as C++, writing a string on one line (even with an uneven number of double-quotes) does not affect proceeding lines. Having this same behavior for VB would be great, assuming that there's some setting to enable it.

推荐答案

是的,很不方便.

我通常做的是放置一些未使用的字符(例如键盘上的一些未使用的符号,或 Alt+{some number})而不是双引号.当我以任何我想要的方式构建我的字符串时,我只是通过打开 Find and Replace 框并用两个双引号替换该字符来完成它.或者直接在它后面放一个 REPLACE 语句,用 Chr(34) 替换那个字符.

What I usually do is put some non-used character (e.g. some unused symbol on keyboard, or Alt+{some number}) instead of double quotes. When I'm done building my string whatever way I want, I just finalize it with either bringing up the Find and Replace box and replace that character with two double-quotes. Or just put a REPLACE statement immediately following it, replacing that character with Chr(34).

这篇关于如何在 VS2015 中禁用自动字符串检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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