question

TryerGit-5098 avatar image
0 Votes"
TryerGit-5098 asked TryerGit-5098 answered

Visual Studio IDE Code snippet to convert field from upper case to lower case

I would like to accomplish the following in a C++ class via a Visual Studio 2019 IDE code snippet:

Link here, reproduced below:

135247-peek-2021-09-26-23-11.gif

which creates a variable name (to hold a constant) in UPPERCASE letters and creates related function names in lowercase of the same name.

The above is accomplished in VSCode via the following code snippet:

 "var set getx":{
         "prefix": "varsetgetx",
         "body":[
             "${1:int} ${2:VARNM};",
             "$1 ${2/(.*)/${1:/downcase}/}(){return $2;}",
             "void ${2/(.*)/${1:/downcase}/}($1 val){$2 = val;}"
         ]
 }


Is there a way to accomplish this in Visual Studio IDE 2019? There seems to be only one other question I could find, but that is from back in 2006, more than 15 years ago. That thread is here.

The answer on that thread unfortunately was that it would not be possible to accomplish something like this. Is it still the case that this is not possible now using the latest VS 2019 IDE?

Thank you.


c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Must you provide a video to explain what you are doing? I cannot understand the video (animation). If you need to do a conversion then you can use text to show the before and after; that would be easier to understand.

0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered TryerGit-5098 edited

The name snippet implies adding code. I think you are trying to change existing code and that is not what snippets are designed for. I think that is what the other answer is saying. If I misunderstand what you are saying then please explain what you need without the animation.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry if the animated gif was unclear. I essentially want to have a snippet indeed to insert 3 lines automatically in a C++ class. These would be the variable name (in capitals) and a setter and getter for the variable, both these being in lower case, suitably overloaded depending on type of the variable.

Example is:

 int VAR;
 void var(int val){ VAR = val;}
 int var() { return VAR;}

In the OP, I accomplish this in VSCode (the animated gif is from VSCode) via the code snippet also specified in the OP. Essentially, I just have to type varsetgetx and then tab through the (1) type of variable, (2) VARIABLE NAME (in capitals) itself. Then, hitting tab takes me to the end of the snippet where the setter and getter are the variable name in lower case.

0 Votes 0 ·
MinxinYu-MSFT avatar image
0 Votes"
MinxinYu-MSFT answered

Hi,

I suggest you directly suggest this feature to Visual Studio Product Team in our Developer Community, and if you do suggest this feature, please share the link here, other forum members who are interested or needed this feature will go to vote for this thread.



Best regards,

Minxin Yu


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TryerGit-5098 avatar image
0 Votes"
TryerGit-5098 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.