x


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)

more ▼

asked Jul 27 '12 at 02:58 PM

alucardj gravatar image

alucardj
13.7k 34 56 87

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

Jul 27 '12 at 03:14 PM alucardj
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jul 27 '12 at 03:08 PM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

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 stemming from the way the .json file is formatted (I'm fairly sure it's tabs that is throwing me off)

Jul 27 '12 at 03:18 PM alucardj

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

Jul 27 '12 at 03:49 PM alucardj
(comments are locked)
10|3000 characters needed characters left

try int.Parse :)

more ▼

answered Jul 27 '12 at 03:06 PM

Seth Bergman gravatar image

Seth Bergman
7k 10 16 28

parseInt maps to System.Int32.Parse as you can see in the exception above ;)

System.Int32 == int
Jul 27 '12 at 03:09 PM Bunny83

sorry I meant int.TryParse maybe still not so useful tho..

Jul 27 '12 at 03:13 PM Seth Bergman
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x420
x205
x10

asked: Jul 27 '12 at 02:58 PM

Seen: 831 times

Last Updated: Jul 27 '12 at 03:49 PM