是否可以在 Visual Studio 中替换为大写?

发布于 2024-08-31 05:14:08 字数 230 浏览 5 评论 0 原文

是否可以在 Visual Studio 中使用“查找和替换”对话框和 RegEx (?) 替换大写字母:。 =>上层(.)

说我有:

m_<b>a</b>blabla

我想要:

_<b>A</b>blabla

Is it possible to replace to upper case in Visual Studio using "Find and Replace" dialog and RegEx (?) à la: . => Upper(.)?

Say I have:

m_<b>a</b>blabla

I want:

_<b>A</b>blabla

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哎呦我呸! 2024-09-07 05:14:08

您可以使用 Visual Studio 临时宏来解决此问题。这是一个非常强大、灵活的功能,我一直使用它来执行重复的代码操作。

我假设您在这里使用 C# 默认键绑定。

  1. CTRL+SHIFT+F 调出“在文件中查找”对话框。
  2. 单击“使用正则表达式”,
  3. 将“查找内容:”设置为“” - 以 m 开头、下划线、小写字母的单词;
  4. 单击“查找全部”可搜索所有出现的情况;
  5. CTRL+SHIFT+R开始录制临时宏;
  6. F8查找下一个出现的搜索表达式;
  7. 按右光标,右光标,SHIFT + 右光标(跳过“m_”,然后选择小写字母);
  8. CTRL+SHIFT+U将小写字母转为大写;
  9. CTRL+SHIFT+R停止录制临时宏;
  10. CTRL+SHIFT+P 重播临时宏,该宏将跳转到下一个表达式并将“m_”后的第一个字母大写。您需要按 CTRL+SHIFT+P 次数,次数与表达式的数量相同。

You can solve this by using Visual Studio temporary macros. This is a very powerful, flexible feature which I use all the time for performing repetitive code manipulations.

I'm assuming you're using the C# default key bindings here.

  1. Press CTRL+SHIFT+F to bring up the find in files dialogue.
  2. Click use "Regular expressions"
  3. Set "Find what:" to "<m_:Ll" - words that begin with m, underscore, then a lower case letter;
  4. Click "Find all" to search for all occurrences;
  5. Press CTRL+SHIFT+R to start recording temporary macro;
  6. Press F8 to find next occurrence of search expression;
  7. Press right cursor, right cursor, SHIFT + right cursor (to skip "m_" and then select the lower case letter);
  8. Press CTRL+SHIFT+U to uppercase the lower case letter;
  9. Press CTRL+SHIFT+R to stop recording temporary macro;
  10. Press CTRL+SHIFT+P to replay temporary macro, which will jump to next expression and uppercase the first letter after the "m_". You need to press CTRL+SHIFT+P as many times as there are expressions.
茶花眉 2024-09-07 05:14:08

如果您使用 Visual Studio Code(而不是 Visual Studio),则可以使用修饰符:\u\U\l\L

  • 示例文本:m_ablabla
  • 查找:m_(.*)
  • ;
  • 替换:m_\U$1替换后的示例文本:m_blabla

注意:这仅在 Visual Studio Code 1.29 及更高版本(2020 年 8 月发布)中可行。请参阅 https://code.visualstudio.com/updates/v1_49# _正则表达式替换中的大小写更改

If you use Visual Studio Code (instead of Visual Studio) you can use the modifiers: \u\U\l\L

  • Sample text: m_<b>a</b>blabla
  • Find: m_<b>(.*)</b>
  • Replace: m_<b>\U$1</b>
  • Sample text after replace: m_<b>A</b>blabla

Note: This is only possible in Visual Studio Code 1.29 and later (released August 2020). See https://code.visualstudio.com/updates/v1_49#_case-changing-in-regex-replace

南笙 2024-09-07 05:14:08

不,Visual Studio 不支持这一点。有关 VS 检查中的正则表达式功能的参考:

正则表达式 (Visual Studio)


(原始答案,由于误解原始问题而给出)

假设 Visual Studio C# 默认键绑定。

您可以通过不同的方式来实现这一目标。

如果它是(变量、方法、属性等),您可以使用重命名重构来更改所有实例。在要重命名的实例上按 F2 键即可调用此重构。

如果您对定义本身进行更改,您还可以使用 SHIFT+ALT+F10 调用活动重构弹出窗口,然后进行重命名所有实例。

如果它是字符串文字,您可以使用快捷键 CTRL+U (小写)和 CTRL+SHIFT+< kbd>U(大写)快速切换所选内容的大小写。这对于编辑器中显示的所有文本都有效,但对于字符串文字最有用。

No, Visual Studio does not support that. For a reference of the regular expressions capabilities in VS check:

Regular Expressions (Visual Studio)


(Original answer, given due to misinterpreting the original question)

Assuming Visual Studio C# Default key bindings.

There are different ways you can achieve this.

If it's a (variable, method, property, etc) you can use the Rename refactoring to change all instances. This refactoring is invoked by pressing F2 key while on the instance you want to rename.

If you perform the change on the definition itself you can also use SHIFT+ALT+F10 to invoke the active refactorings popup and then do the rename all instances.

If it's a string literal you can use the shortcut CTRL+U (lowercase) and CTRL+SHIFT+U (uppercase) to rapidly switch the case of the selection. This is valid for all text shown in the editor, but most useful for string literals.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文