views:

56

answers:

1

Hi

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 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

A: 

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.

Jan Goyvaerts
Jan, your tip was very useful for me to find a solution.What I did was:field "find what": (Session\(){.*}(\))field "replace whit": Session\[\1\]And it worked exactly like I wanted.Thanks
William John Adam Trindade