title: Finding unknown repeating patterns in a string consisting numbers
body: <p>I've been struggling with this for a week.</p>
  
  <p>I have a string like this: <strong>1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1.....</strong></p>
  
  <p>What I need to find: <strong>1 1 0</strong></p>
  
  <p><br></p>
  
  <p>example 2: <strong>1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 1 1 2 0 2 2 1 0 ....</strong></p>
  
  <p>What I need to find: <strong>1 1 2 0 2 2 1 0</strong> </p>
  
  <p><br></p>
  
  <p>example 3: <strong>1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0 1 1 2 3 1 0...</strong></p>
  
  <p><strong>112310</strong></p>
  
  <p><br></p>
  
  <p>etc. etc.</p>
  
  <p>My code as now:</p>
  
  <pre><code>private string tekrarArama(double[] mods)
          {
              string part1 = "";
              string part2 = "";
  
              string patern = "";
  
  
              int number1 = mods.Length;
  
              for (int i = 0; i &lt; mods.Length; i++)
              {
                  part1 = "";
                  part2 = "";
                  for (int j = 0; j &lt; number1; j++)
                  {
  
                      part1 += mods[j] + ",";
                  }
  
  
                  for (int k = 0; k &lt; mods.Length; k++)
                  {
  
                      part2 += mods[k] + ",";
                  }
  
  
                  int actualcount = Regex.Matches(part2, part1).Count;
  
                  int count = part2.Replace(",", "").Length / part1.Replace(",", "").Length;
  
  
                  if (part2.IndexOf(bolum1) &gt;= 0 &amp;&amp; actualcount == count )
                  {
                      patern = part2.Substring(part2.IndexOf(part1),part1.Length);
                  }
  
                  number1--;
  
  
              }
  
              return patern;
  
          }
  </code></pre>
  
  <p>It creates two copies of the string and deletes 1 character at a time from one of the strings in each iteration, to find the smallest repeating pattern. </p>
  
  <p>It's a mess and doesn't work very well at all. 
  How can I do this? Thanks in advance.</p>