简体   繁体   中英

How to change a string into integer

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM