In vs.net, I want to search for all occurances of
[someWord]
in my .sql file, and replace it with
[SomeWord]
Is this possible? (notice the uppercasing of the first character in the result)
Yes you can do Regex searches/Replaces in vs.net, just make sure to check the box in the dialog. The regex syntax is different from the Perl/.Net one though. Pay attention to the differences in syntax.
There's some reference here:
http://www.codinghorror.com/blog/archives/000633.html
If it's just a certain word:-
s/\[someWord\]/[SomeWord]/
But it might just be better to use a replace function
If it's anything in square brackets.
s/\[[a-zA-Z]+\]/[\u\1]/
Not sure but you might open that sql file externally is some editor like notepad++ and replace the stuff accordingly.
Here, this is VS Addin for regex search and replace found on CodeProject. Be warned that the code was for VS 2003, but can be recompiled I'm sure for later versions of VS.NET.
Hope this helps,
Best regards,
Tom.
Related
I like CodeRush QuickPair feature.
Does anybody know how to remove quotes or braces with a shortcut?
For example:
Can I select
"some string"; // with quotes
and remove quotes with a shortcut and will get
some string; // without quotes
or select
(someArgument); // with braces
and remove braces and will get
someArgument; // without braces
If I'm understanding you correctly, CodeRush does not contain this functionality at present.
However it sounds like the kind of thing that could be created as a plugin quite quickly.
If you update your question to include some before and after examples, I'm confident I could create such a plugin for you.
Update: I have created a plugin to fulfil the first requirement. That of removing Quotes from around a string.
The source is published on github and you can download the VSIX here
Could you provide a little more context in your 2nd example? It does not appear to be syntactically correct C#.
I'm interested to see what sort of code you would perform this operation on. This is also necessary in order to make the plugin available in the correct context.
I'm looking for a way to include code as part of a paragraph in DokuWiki like I can by adding backtick escapes in StackOverflow like _so_. Simply adding <code>bla</code> puts code on it's own line.
You probably want to use ''%%here is code%%''. This formats it in monospace ('') and prevents any interpretion of possible wiki markup (%%).
I was able to find an answer to my own question. Add quotes around the in-text code ''like this''. Simple, short, and works great.
I am refactoring a C++ codebase in Visual Studio 2005. I'm about half way through this process now and I've commented out a lot of old code and replaced or moved it. Now I'm searching to see that I have to change next but the search function keeps bringing me the old commented out stuff I no longer care about. I don't really want to delete that old code yet, just in case.
Is there any way I can search all files in the solution and get results ignoring what is commented out? I don't see a way in visual studio itself, is the perhaps a plug-in that would do it?
As the other provided solutions didn't work for me, I finally discovered the following solution:
^~(:b*//).*your_search_term
Short explanation:
^ from beginning of line
~( NOT the following
:b* any number of white spaces, followed by
// the comment start
) end of NOT
.* any character may appear before
your_search_term your search term :-)
Obviouly this will only work for // and ///-style comments.
You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search
In newer versions of visual studio .net regex is used which has a slightly different syntax:
^(?![ \t]*//).*your_search_term
My take:
yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.
I prefer non-obtrusive semi-inteligent methods:
Poor man's method:
Find references if you happen to use intelisense on
Or even better:
Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.
If you comment your old code with // you can use regular expressions while searching for something in your codebase. Something like this for example: ^[^/][^/].*your_function_name.*.
Previous answer gave a false-positive on cases where otherwise matching lines were placed on lines containing other source:
++i; // your_search_term gets found, don't want it found
So replaced the :b* with .* and added the <> so only entire words are found, and then went after some of the older C-style comments where there's a /* on the line:
^~(.*//)~(.*/\*).*<your_search_term>
In my case I was hunting for all instances of new, not amenable to refactor assistance, and boatloads of false-positives. I also haven't figured out how to avoid matches in quoted strings.
Just to add on, as I was doing a "find all" for division operator used in the code, used the below to exclude comments as well as </ and /> from aspx files:
^~(.*//)~(.*/\*)~(.*\<\/)~(.*/\>).*/
In Visual Basic within Visual Studio 2015, I was able to search for text outside of comments by adapting glassiko's comment from the most upvoted answer
^(?![ \t]*[']).*mysearchterm
And in C# you would use glassiko's comment exactly as it was
^(?![ \t]*//).*mysearchterm
Better use \s I think. ^(?![\s]*//).*your_search_term
delete the commented out code, it is in source control right? there is no need to keep it in the file as well.
TextMate may be the best editor out there, but is has a big disadvantage: it undoes each character typed instead of grouping characters. This makes a large undo tedious!
Do you now any hacks, plugins or workarounds to fix this issue?
I know the developer's been promising a fix for years now, and it's something the user community complains about a lot. But I don't think I've seen anything more useful than "hold down Cmd-Z to repeat".
This is not exactly what you're asking for but more a work around because as dnord said, this is a fundamental issue with TextMate and won't be fixed until Allen Odegard decides to fix it.
Have you considered trying one of the clipboard managers out there? At least that way you can clip chunks of text and 'undo' them at will.
I use Jumpcut because it's free and does the job.
Just in case anyone doesn't already know this: Shift-Option-Arrow lets you select things word by word.
If you make a habit of selecting whole words before deleting text, you'll save time when you do and when you undo.
I have a solution with multiple projects and we need to do some serious global replacements.
Is there a way to do a wildcard replacement where some values remain in after the replace?
So, for instance if I want every HttpContext.Current.Session[“whatevervalue”] to become HttpContext.Current.Session[“whatevervalue”].ToString() the string value being passed in will be respected? I don’t want to replace “whatevervalue” I just want to append a .ToString() where the pattern matches.
Is this possible in Visual Studio?
First, Backup your Projects, just in case... Always a good idea before mass replacements.
Then, in the Find/Replace Dialog, select the Use Regular Expressions checkbox:
In the Find box, use the pattern:
HttpContext\.Current\.Session\["{.#}"\]
and in the Replace box, use:
HttpContext.Current.Session["\1"].ToString()
Easy...use regular expressions and grouping.
Find what:
(HttpContext.Current.Session[“whatevervalue”])
Replace with:
\0.ToString();
Remember to check the Use: and select Regular expressions
You want to open the "Find Options" expander and select the "Use Regular Expressions" option. After you've done that, you want these as your find/replace entries:
Find:
HttpContext\.Current\.Session\[{("([^"]|\")*")}\]
Replace:
HttpContext.Current.Session[\1].ToString()
Additional Note:
Once you've enabled regular expressions option, you'll be able to use the right-pointing triangle buttons to access snippets of Visual Studio's Regex syntax.
Also note that Visual Studio's Regex syntax is pretty ghetto, as it hasn't changed since the days of Visual Studio 6 (or earlier?)--so don't take any syntax elements for granted.
For example, one might expect that my find regex above is broken because the backslash before the double-quote is not properly escaped, but in reality, putting a double-backslash there will break the expression, not fix it.
None of these answers seem to work in Visual Studio 2013, as that version seems to have finally made the switch to standard RegEx. However, those who are non-RegEx Experts or those who are used to the old VS Find/Replace RegEx syntax will find the RegEx Shortcut buttons very useful.
Please see this answer for more information, including Find/Replace/Surround With examples:
Visual Studio 'Find and Surround With' instead of 'Find and Replace'
You can use Visual Assist for tasks like this. It's a powerful tool for different kinds of refactoring.
You could also consider using the free download tool Refactor available at http://www.devexpress.com/Products/NET/IDETools/RefactorASP/
It does a whole lot more than just find & replace, which they call renaming members with more understandable names. Its various features will easily help you to improve your code.