title: Unable to extract signed decimal numbers from string in Xamarin.Android
body: <p>I am aware similar questions have been asked here before, but I have not found anything that works for me, so I am desperate.</p>
  
  <p>I am receiving a number of values from Bluetooth, which are separated by commas, and I receive them as string. They can be both positive or negative decimal numbers. For example:
  0, 1.11, 2.22, -3.33, -4.44, 55.55, 66.66, -77.77, 8.88, 0</p>
  
  <p>I am however unable to extract all the numbers as they are. I have tried Regex, I have tried splitting and parsing, I have tried parsing to decimal, double, however I get unhandled exceptions for the Parse functions every single time. </p>
  
  <p>Any help for a definitive solution is appreciated.</p>
  
  <p>EDIT:
  Here's the part of the code where I'm trying to parse:</p>
  
  <pre><code>    public static void AddToGraphs(string list) {
      try
      {
          var data = list.Split(',').Select(x =&gt; double.Parse(x, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture));
          double[] dataArray = data.ToArray();
      }
      catch (Java.IO.IOException e)
      {
          Log.WriteLine(LogPriority.Error, e.Source, e.Message);
      }
  }
  </code></pre>
  
  <p>Here's the call stack when the app crashes:</p>
  
  <pre><code>        0xFFFFFFFFFFFFFFFF in 
      System.Diagnostics.Debugger.Mono_UnhandledException_internal    C#
              0x1 in System.Diagnostics.Debugger.Mono_UnhandledException  C#
              0x26 in object.6f90deee-2618-4e76-9135-3c21efb2de46 C#
  
  
      0x96 in System.Number.ParseDouble   C#
          0x3 in double.Parse C#
          0xE in double.Parse C#
          0x8 in Namespace.&lt;&gt;c.&lt;AddToGraphs&gt;b__38_0   C#
          0x26 in System.Linq.Enumerable.SelectArrayIterator&lt;string,double&gt;.ToArray  C#
          0x20 in System.Linq.Enumerable.ToArray&lt;double&gt;  C#
          0x37 in Namespace.Page3Fragment.AddToGraphs C#
          0x5A in Namespace.Page1Fragment.MyHandler.HandleMessage C#
          0x11 in Android.OS.Handler.n_HandleMessage_Landroid_os_Message_ C#
          0x17 in object.6f90deee-2618-4e76-9135-3c21efb2de46 C#
  </code></pre>
  
  <p>EDIT:
  This is the logcat, with the 'list' variable logged, just before the app crashes:</p>
  
  <pre><code>Time    Device Name Type    PID Tag Message
  07-31 00:55:30.097  Samsung SM-G610F    Info    32398   Test    0
  07-31 00:55:30.157  Samsung SM-G610F    Info    32398   Test    , 1.11, 2.
  </code></pre>
  
  <p>EDIT:
  This is the the Bluetooth Service which is sending the received data to the handler:</p>
  
  <pre><code>byte[] buffer = new byte[8192];
  int bytes;
  while (true)
  {
      bytes = ipStream.Read(buffer, 0, buffer.Length);
      try
      {
          myService.myHandler.ObtainMessage(Page1Fragment.DATA_READ, bytes, -1, buffer).SendToTarget();
      }
      catch (Java.IO.IOException e)
      {
          throw e;
      }
  }
  </code></pre>
  
  <p>Here's the snippet of the handler where it is received and passed to the AddToGraphs function:</p>
  
  <pre><code>private class MyHandler : Handler
  {
      Page1Fragment page1;
      public MyHandler(Page1Fragment _page1)
      {
          page1 = _page1;
      }
      public override void HandleMessage(Message msg) 
      {
          byte[] readBuf = (byte[])msg.Obj;
          string inData = Encoding.ASCII.GetString(readBuf, 0, msg.Arg1);
          Page3Fragment.AddToGraphs(inData);
      }
  }
  </code></pre>