How to change a string into integer

I have to change s string to integer

var floorname = coll.collider.gameObject.name;
   
var cur = floorname.Substring(5);	
	
var cu = parseInt(cur);

But while giving print(cu); it shows value. but with a error
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s)

How can i clear this?

Thanks in Advance

This worked correctly for me when testing the following code:

function Start()
{
    var numberString = "12";
    var number = parseInt(numberString);
    print(number);
}

However, if you change the “numberString” variable to some value that is not a number (like “foobar”), you get the exception you describe in your question.

It seems most likely that your “floorname.Substring” call is either not returning a string that represents a number, or it is returning a number with some extra characters, like “d12” or something. If you pass a string to parseInt that isn’t actually a number, it seems to give this exception.

Removed whitespaces by using

cur = cur.Trim(); 

which works properly.