c# dynamically pass string method at run time for string manipulation
<p>How do I dynamically pass string methods to be applied to strings at run time. 
ex.</p>

<pre><code>Private String Formatting(String Data, String Format)
</code></pre>

<p>When we pass <code>String S1 = "S1111tring Manipulation"</code> and <code>format = Remove(1,4)</code> - behind the scenes it becomes <code>S1.Remove(1,4)</code> resulting in "String Manipulation"</p>

<p>or if we pass <code>String  S1 = "S1111tring Manipulation"</code> and <code>format = ToLower()</code> behind the scene it becomes <code>S1.ToLower()</code> resulting in <code>"s1111tring manipulation"</code></p>

<p>I should be able to pass any valid method like <code>PadLeft(25,'0')</code>, <code>PadRight</code>, <code>Replace</code> etc...</p>

<p>I would appreciate a complete example</p>

<p>This is what I have tried and it does not work</p>

<pre><code>using System.Reflection;
string MainString = "S1111tring Manipulation";
string strFormat = "Remove(1, 4)";
string result = DoFormat(MainString, strFormat);

private string DoFormat(string data, string format)
        {
            MethodInfo mi = typeof(string).GetMethod(format, new Type[0]);
            if (null == mi)
                throw new Exception(String.Format("Could not find method with name '{0}'", format));

            return mi.Invoke(data, null).ToString();
        } 
</code></pre>

<p>throws an error (Could not find method with name 'Remove(1, 4)') - so I am not sure how to proceed</p>
