Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Parsing a negative String number ERROR

Discussion in 'Scripting' started by vhagharvhaghar, Aug 27, 2016.

  1. vhagharvhaghar

    vhagharvhaghar

    Joined:
    Feb 19, 2015
    Posts:
    16
    I have my levels setup in an xmlFile, the objects's positions are represented in a string something like this
    <Position>0,1,0</Position>
    <Position>-1,0,0</Position>​
    my problem occurs when I try to parse the Strings that contains a negative number, The code throws a Format Exception, I literally tried everything i know or saw on the net, nothing worked

     
  2. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    what language are you using how have you tried to parse the string? In c# this will work:
    using System;
    int x = Convert.toInt32("-1"); // x will = -1
     
  3. vhagharvhaghar

    vhagharvhaghar

    Joined:
    Feb 19, 2015
    Posts:
    16
    All good, the thing is when I tried to split the Position String I put a "-" in the seperator, Removed that and everything was fixed