开发者

Conversion VB -> C #. Regular expression to modify ("abc") in ["abc"]

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜