Convert int to string and back again

Hi all, I’m having a problem after I convert one of my int’s to a string…I can’t get it to convert back to an int! Here’s some sample code to show you what i’m dealing with.

var price : int;

function IntToString() {
price.ToString();
}

function StringToInt() {
price = System.Int32.TryParse(price); <<<ERROR HERE
}

I’m getting the error “No appropriate version of int.TryParse for the argument list ‘(int)’ was found.”

Can someone give me an idea what I’m doing wrong? Thank you!

Here you go:

 var nu1: int = 100;
 var str: String ="";
 var nu2: int;

 // Convert int to string
 str= nu1.ToString();

 // Convert string to int
 nu2=System.Int32.Parse(str);

 Debug.Log(nu1);
 Debug.Log(str);
 Debug.Log(nu2);

According to the documentation of TryParse, it wants two parameters, a string and an output int … see:

http://docs.mono-android.net/?link=T%3aSystem.Int32%2fM%2fTryParse

Did you perhaps mean to use the Parse() method? See:

http://docs.mono-android.net/?link=T%3aSystem.Int32%2fM%2fParse

This however would also not work as in your code you are passing in “price” which is an int and both Parse() and TryParse() expect a String as input.