0
public class ChemDB : MonoBehaviour 
{
    private int i;
    void Start ()
    {
        string[] lines = System.IO.File.ReadAllLines("Assets/Scripts/Data/Database.txt");
        int perioada=0,grupa=0,nrAt=0,masa=0,valenta=0,a=0,b=0,c=0,d=0,e=0,f=0,g=0;
        string Nume,Simbol,Tip,Stare;
        for(i=1;i<=118;i++)
        {
            Int32.Parse(lines[(i-1)*16],perioada);
            Int32.Parse(lines[1+(i-1)*16],grupa);
            Int32.Parse(lines[2+(i-1)*16],nrAt);
            Nume=lines[3+(i-1)*16];
            Simbol=lines[4+(i-1)*16];
            Int32.Parse(lines[5+(i-1)*16],masa);
            Int32.Parse(lines[6+(i-1)*16],valenta);
            Tip=lines[7+(i-1)*16];
            Stare=lines[8+(i-1)*16];
            Int32.Parse(lines[9+(i-1)*16],a);
            Int32.Parse(lines[10+(i-1)*16],b);  
            Int32.Parse(lines[11+(i-1)*16],c);
            Int32.Parse(lines[12+(i-1)*16],d);
            Int32.Parse(lines[13+(i-1)*16],e);
            Int32.Parse(lines[14+(i-1)*16],f);
            Int32.Parse(lines[15+(i-1)*16],g);

        }
    }
}

I'm using Unity C#.I get thhis error "The best overloaded method match for `int.Parse(string, System.IFormatProvider)' has some invalid arguments." and i don't understand what i'm doing wrong.

Zadak Leader
  • 29
  • 11

1 Answers1

0

Int32.Parse taskes the string as the first parameters, and returns the number as an int.

You are passing the variable to store the int as the second parameter like this:

Int32.Parse(lines[(i-1)*16],perioada);

It should be used like this:

perioada = Int32.Parse(lines[(i-1)*16]);

Thats why you are getting the error, because the second optional parameter is used to define the format of the string passed in the first parameter. But since you are using an int, the types don't match.

Leo
  • 1,174
  • 11
  • 25
  • FormatException: Input string was not in the correct format System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Int32.cs:629) ChemDB.Start () (at Assets/Scripts/ChemDB.cs:17) – Zadak Leader Feb 20 '15 at 10:15
  • I am positive the string in those parameters are of type int, the others are string – Zadak Leader Feb 20 '15 at 11:07
  • Output the value of lines[(i-1)*16] and post them here in the comment – Leo Feb 20 '15 at 11:10
  • It was (i-1) * 17 thanks for pointing me in the right direction :) – Zadak Leader Feb 20 '15 at 13:17