In C# VS2008 how to replace
intA = (int)obj.GetStr("xxx");
to
intA = int.Parse(obj.GetStr("xxx"));
I have thounds of lines code have this pattern. I just want to pass compile by using some regular expression.
In C# VS2008 how to replace
intA = (int)obj.GetStr("xxx");
to
intA = int.Parse(obj.GetStr("xxx"));
I have thounds of lines code have this pattern. I just want to pass compile by using some regular expression.
Have you tried Search and Replace?
Search for 'intA = (int)obj.GetStr("', replace with 'intA = Convert.ToInt32(obj.GetStr("'.
I don't like the new version either. When you know you have a string, int.Parse()
or int.TryParse()
is probably more appropriate.
Try search and replace using the following regex:
EDIT: Replace the AAA, BBB, CCC values with the appropriate method names you want to match and replace. Be careful of using the :i (identifier) match predicate, as that would match any method call - which you probably don't want.
Find: (looks for any call on any expression to GetStr)
\(int\){.+}\.{(GetStr|AAA|BBB|CCC)}\({.*}\);
Replace With:
Convert.ToInt32(\1.\2(\3));
or (as others have mentioned) replace with:
Int.Parse(\1.\2(\3));
This is a variation on what LBushkin suggested:
find: \(int\){:i\.:i\(:q\)}
replace: int.Parse(\1)