如何在 Visual Studio 中将代码中的字符串转换为大写?
我试图将文件中与特定正则表达式匹配的所有字符串转换为大写,但在 Visual Studio 的“查找和替换”窗口中找不到指定该字符串的语法。是否可以使用 Visual Studio 正则表达式来执行此操作?
I'm trying to convert all character strings that match a particular regex in a file to uppercase, but I can't find the syntax to specify that within the 'Find and replace' window in Visual Studio. Is it possible to do this using the Visual Studio regex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 JaredPar 所解释的,这不能使用通用正则表达式搜索/替换来完成。但是,我想您应该能够使用 来执行此操作宏。
As JaredPar has expained, this cannot be done using a generic regular expression search/replace. However, I guess you should be able to do this using a macro.
无法使用 Visual Studio 正则表达式将其作为通用替换。可以使用 \n 转义序列将捕获的文本重新用作替换字符串的一部分,其中 n 表示第 n 组捕获的文本。然而,正则表达式语言仅支持对此文本的有限修改(主要是理由更改)。它不允许您更改大小写。
以下是 Visual Studio 正则表达式语言的链接
It's not possible to do this as a generic replacement using Visual Studio regular expressions. It is possible to re-use the captured text as part of a replacement string using the \n escape sequence where n represents the nth group of captured text. However the regex language only supports limited modifications on this text (mostly justification changes). It doesn't allow you to change case.
Here is a link to the Visual Studio regex language
当查找窗口获得焦点时按 alt + 'e' 以启用“正则表达式”搜索。
当然,您无法“编程”一组替换选项以根据找到的内容插入。每套替换品都需要一次通过。
press alt + 'e' when the find window has focus to enable "regex" searches.
naturally, you can't 'program' a set of replacement options to insert based on what is found. Each replacement set would require one pass.