[Solved] How can i convert the string to int and count? [closed]


EDIT

for this code to work

  X  = string.Format("Frame_X_{0} ", i + 1);
  Y  = string.Format("Frame_Y_{0} ", i + 1);
  int c = Convert.ToInt32(ExtractNumbers(X));//modfied code line
  int d = Convert.ToInt32(ExtractNumbers(Y));//modfied code line
  framesNumberX += c;  framesNumberY += d;

you need to extract number something like this

static string ExtractNumbers( string expr )
{
 return string.Join( null,System.Text.RegularExpressions.Regex.Split( expr, "[^\\d]" ) );
}

Prev Ans

Good way to do is

static void Main()
    {
    // Convert string to number.
    string text = "123";
    int num = -1;
      if( int.TryParse (text,out num))
    Console.WriteLine(num);
    }

check that string is convertable or not

5

solved How can i convert the string to int and count? [closed]