Frage

I have to change a string into integer

var floorname = coll.collider.gameObject.name;   //output:block25

var cur = floorname.Substring(5);    //output: 25

var cu = parseInt(cur);

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

How can i clear this?

War es hilfreich?

Lösung

Microsoft's documentation says whitespace is okay in the integer string, but I'm not sure if that includes newline.

http://msdn.microsoft.com/en-us/library/f56zcx39(v=vs.90).aspx

It's safest to use String.Trim() before parsing the integer.

cur = cur.Trim();

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top