We are currently converting our old base VB.Net to C #. Converting the bulk of the code is not a problem .. there are good converters around. The problem we are facing is that none of the tested converters can convert () in [] in arrays and collections.
Example: Session ("abcd") to Session ["abcd"];. Converters think Session is a method/function and leave开发者_JAVA技巧 with the parenthesis.
My question is: is there any regular expression that can be used in find/replace in Visual Studio 2008 that can make this substitution? Why do it manually to get tired when you have to do it over 200 times per class.
Thank you for attention
If you want to automate this, you need a converter that can parse VB.NET code like a compiler would.
If you just want to replace Session (whatever)
with Session [whatever]
, you can search for the regular expession (Session *)\((.*?)\)
and replace with $1[$2]
. Or search for ((?:Session|otherkeyword|thirdkeyword) *)\((.*?)\)
and replace with the same if there are multiple keywords that can precede your arrays.
My regexes are Perl-style. They'll work in many modern text editors as well as with .NET's Regex class. The VS IDE has its own regex flavor that's not really compatible with anything else.
精彩评论