質問

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?

役に立ちましたか?

解決

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();

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top