Converting from binary to unary I have function that convert binary number to unary number based on a Markov algorithm. In what ways can I improve the code?

The algorithm goes as follows:


Replace all 0l with 0l


  "|0" -&gt; "0||" 

Replace all l0 with 0ll


  "1" -&gt; "0|"

Major Step 3: Remove the 0


  "0" -&gt; ""




    public List BinaryToUnary(List value)
    {
        var temp = new List();
        var temp2 = new List();
        var temp3 = new List();
        string hold = "";
        int count = 1;


        TxtToDisPlay = "Major Step 1: replace All 1 with 0l userInput " + string.Join("", value) + "\n\n";

        foreach (var x in value)
        {
            if (x.Equals("1"))
            {
                temp.Add("0l");
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + x + " = " + "0l" + "\n";
            }
            else
            {
                temp.Add(x);
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + x + " = " + x + "\n";
            }
            count++;
        }
        TxtToDisPlay = TxtToDisPlay + "\n\nMajor Step 2: Replace all l0 with 0ll  userInput = " + string.Join("", temp) + " \n\n";

        foreach (var x in string.Join("", temp))
        {
            hold = hold + x;
            if (hold.Equals("l0"))
            {
                temp2.Add("0ll");
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + "0ll" + "\n";
                hold = "";
            }
            if (hold.Equals("0"))
            {
                temp2.Add(hold);
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "\n";
                hold = "";
            }
            count++;
        }
        if (hold.Equals("l"))
        {
            temp2.Add("l");
        }


        hold = "";

        foreach (var y in string.Join("", temp2))
        {
            if (temp2.Count == 1)
            {
                temp3.Add("l");
                break;
            }

            hold = hold + y;
            if (hold.Equals("l0"))
            {
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + "0ll" + "\n";
                temp3.Add("0ll");
                hold = "";
            }
            if (hold.Equals("0") || hold.Equals("ll"))
            {
                if (hold.Equals("ll"))
                {
                    TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "\n";
                    temp3.Add("l");
                    hold = "l";
                }
                else
                {
                    TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + hold + " = " + hold + "\n";
                    temp3.Add(hold);
                    hold = "";
                }

            }
        }
        if (value.Count == 3 && hold.Equals("l"))
        {
            temp3.Add("l");
            temp3.Add("l");
        }
        else if (value.Count == 3 || hold.Equals("l"))
        {
            temp3.Add("l");

        }

        TxtToDisPlay = TxtToDisPlay + "\n\nMajor Step 3 : get rid of the 0 from  userInput = " + string.Join("", temp3) + " \n\n";
        var answer = new List();
        foreach (var x in temp3)
        {
            if (x.Contains("0ll"))
            {
                foreach (var y in x.Where(y => y.Equals('l')))
                {
                    answer.Add("l");
                    TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + "x = l so " + "Add l To new Array result = " + string.Join("", answer) + "\n";
                }
            }
            else if (x.Contains("l"))
            {
                TxtToDisPlay = TxtToDisPlay + "Step " + count + ": " + "Add l To new Array result = " + string.Join("", answer) + "\n";
                answer.Add(x);
            }
            count++;
        }

        return answer;
        }
You are not supposed to replace all matches but only the first one. And then repeat the process.

Here is some javascript code that implements the markov algorithm exactly the way it is described on the wikipedia page.
Now all you have to do is translate that to C#.

function binaryToUnary(value) {
  var matchFound = false,
      rules = [["|0", "0||"],
               ["1",  "0|" ],
               ["0",  ""   ]];
  do {
    matchFound = false;
    for(var i = 0; i &lt; rules.length; i++) {
      var rule = rules[i],
          pattern = rule[0], replacement = rule[1],
          index = value.indexOf(pattern);
      if(index &gt;= 0) {
        value = value.substring(0, index) +
                replacement +
                value.substring(index + pattern.length);
        matchFound = true;
        break; //break because only the first pattern that matches should be replaced
      }
    }
  } while(matchFound);
  return value;
}