문제

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