Check source contain replace string I created this function  it is looking for the html tag  and replacing it with the ^value. It seems complicated wanted to know if there is a better way to do something like this.


  Will you review the syntax, structure, and logic of my code. It can be tested using the main.


Output

dsfsadfsad 5&lt;sup&gt;8&lt;/sup&gt; dsfsadfsad
dsfsadfsad 5^8  dsfsadfsad


Code

namespace Replacestring
{
    class Program
    {
        static void Main(string[] args)
        {

            string source = "dsfsadfsad 5&lt;sup&gt;8&lt;/sup&gt; dsfsadfsad";
            Console.WriteLine(source);
            source = superscriptRule(source);
            Console.WriteLine(source);

        }

        protected static string superscriptRule(string source)
        {
            if (!string.IsNullOrEmpty(source) == true)
            {
                if (source.Contains("&lt;sup&gt;"))
                {
                    Match m = Regex.Match(source, @"&lt;sup&gt;\s*(.+?)\s*&lt;/sup&gt;", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        int i = 0;
                        string x = m.Groups[1].Value;
                        bool result = int.TryParse(x, out i);
                        if (result == true)
                        {
                            string replacestring = string.Format("&lt;sup&gt;{0}&lt;/sup&gt;", x);
                            string newstring = string.Format("^{0} ", x);
                            source = source.Replace(replacestring, newstring);
                            return source;
                        }
                        else
                        {
                            return source;
                        }
                    }
                    return source;
                }

            }
            return source;

        }
    }
}
Method names should be named using PascalCase casing.  
An if condition is just a boolean expression hence if (!string.IsNullOrEmpty(source) == true) is a little bit over the top. Either write  

if (!string.IsNullOrEmpty(source))
{

}


or   

if (string.IsNullOrEmpty(source)) { return source; }  


which saves one level of indentation.  
Why is the method protected ? Doesn't make sense to me.
The name of that method sounds rather like a class/object name than a method name. Methodnames should contain a verb or verb-phrase.


Instead of the Regex stuff and string.Contains() etc your method could just look like so  

private static string SuperscriptRule(string source)
{
    if (string.IsNullOrEmpty(source)) { return source; }

    return source.Replace("&lt;sup&gt;", "^").Replace("&lt;\sup&gt;", string.Empty);
}