title: sum multiple digits if cell contains some symbols
body: <p>I have a datagridview where I'm counting the value from a column and multiply for another column value, then do the sum for all the rows and display the result in label with this code:</p>
  <pre><code>int sum2 = 0;
              for (int m = 0; m &lt; dataGridView1.Rows.Count; ++m)
              {
                  sum2 += getCellRepsSum(dataGridView1.Rows[m]);
              }
       
          label18.Text = sum2.ToString();
  
  
         
  
          int getCellRepsSum(DataGridViewRow dr)
          {
              int serie = Convert.ToInt32(dr.Cells[1].Value);
  
  
              int l = Convert.ToInt32(dr.Cells[2].Value); //reps
  
  
              int result = 0;
  
  
  
              result = serie * l;
              return result;
          }
  </code></pre>
  <p>This works fine if I set a number, but what I want to add a condition based on the presence of symbols like + or -.</p>
  <p>So something like... if cell value of &quot;ripetizioni&quot; column contains &quot;-&quot; or &quot;+&quot; then sum the numbers between each symbols and then multiply like my code do.</p>
  <p>Example: 12-8-6 need to sum 12 + 8 + 6 then multiply for &quot;serie&quot; column like in my code etc.</p>
  <p>I've tried like this but don't work because the &quot;-&quot; symbol doesn't permit the ToInt Conversion:</p>
  <pre><code>int sum2 = 0;
              for (int m = 0; m &lt; dataGridView1.Rows.Count; ++m)
              {
                  sum2 += getCellRepsSum(dataGridView1.Rows[m]);
              }
       
          label18.Text = sum2.ToString();
  
  
         
  
          int getCellRepsSum(DataGridViewRow dr)
          {
              int serie = Convert.ToInt32(dr.Cells[1].Value);
  
              int result = 0;
              string l = Convert.ToString(dr.Cells[2].Value);
  
              if (l.Contains(&quot;-&quot;)) {
  
                  int lt = Convert.ToInt32(dr.Cells[2].Value);
                  int sumReps = 0;
  
                  
  
                  while (lt &gt; 0)
                  {
                      sumReps += (lt % 10);
  
                      lt = lt / 10;
                  }
                  result = sumReps;
                  return result;
  
              }
              else {
                  //reps
  
                  int li = Convert.ToInt32(dr.Cells[2].Value); //reps
  
  
  
  
                  result = serie * li;
                  return result;
              }
              
              return result;
          }
  </code></pre>
  <p>How can I solve this?</p>