Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

Can anybody help me with writing a regular expression which will find and Replace
someVariable.ToString()

to

Convert.ToString(someVariable)

Let me know if this is Possible or i am just expecting too much :-)

Reference:
http://office.microsoft.com/en-in/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx[^]

Visual Studio Find/Replace Regular Expression Usage[^]
Posted
Updated 25-Mar-14 4:01am
v2
Comments
Matt T Heffron 25-Mar-14 14:42pm    
The problem you're likely to find is that your calls to .ToString() will not necessarily be just from a variable, but possibly some expression.
E.g.:
(integerVariable1 + integerVariable2).ToString()
or
someMethod(arg1, arg2).ToString()
A regex to handle any possible cases is not likely to be practical.
Also, what about the cases where there are parameters to the .ToString().....?

1 solution

<variable>.TOString() and Convert.TOString(<variable>) both will work. But if Variable have a null value then <variable>.TOString() will raise a nullException.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900