开发者

Is it possible to replace to uppercase in Visual Studio?

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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜