- Home /
parseInt a String not working
After parsering a text file into an array, I cannot typecast a value within from a string to an int. This usually works for me so I am clueless as to why this is breaking :
//textureInfo.x = parseInt( _words[i + 3 + 2] );
var valueX = ( _words[i + 3 + 2] ).ToString();
textureInfo.x = parseInt( valueX );
Error :
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s)
UnityScript.Lang.UnityBuiltins.parseInt (System.String value)
Thanks to both. It seems I am being bitten by the same *&^$% problem as in my other question : http://answers.unity3d.com/questions/291545/remove-tab-from-parsed-string.html
After running a test to check the length, it is showing one more character than I am expecting.
Debug.Log( "_words[" + (i + 3 + 2) + "].Length " + _words[i + 3 + 2].Length );
Why is it I managed to write a reader for .fnt info files , but parsering a texpacker .json is giving me so much hassle ?
I am already cheating on the above question by using
var newString = _word1;
var index = newString.Length;
if (index > 1)
{
newString = newString.Remove( 0, 1 );
}
http://answers.unity3d.com/questions/291294/stringequals-not-working-as-expected.html
Answer by Bunny83 · Jul 27, 2012 at 03:08 PM
The error clearly says that the string you pass in is malformed / doesn't contain a number that can be converted. The first thing you should check is: What is in this string! Debug.Log might help.
That is the answer to my question I think. When you posted this I was running a debug as it was the same thing in my other question. It's all stem$$anonymous$$g from the way the .json file is formatted (I'm fairly sure it's tabs that is throwing me off)
Well I goofed up on this one. I hadn't removed the commas on this script. So thanks. Although my problem with tabs is still definitely valid : http://answers.unity3d.com/questions/291545/remove-tab-from-parsed-string.html
Answer by Seth-Bergman · Jul 27, 2012 at 03:06 PM
try int.Parse :)
parseInt maps to System.Int32.Parse as you can see in the exception above ;)
System.Int32 == int
sorry I meant int.TryParse maybe still not so useful tho..
Your answer
Follow this Question
Related Questions
Extract number from string? 3 Answers
Why does SystemInfo.deviceUniqueIdentifier fail to return the same string? 0 Answers
Accessing local system ( File Browser ) 2 Answers
Is it possible for parseInt("5+5") to return 10? 2 Answers
parseInt givin' me issues! 2 Answers