foreach (object item in listBox1.SelectedItems)
{
string curItem = item.ToString();
var parts = curItem.Split("{}XY=, ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
var xCoord = float.Parse(parts[0]);
var yCoord = float.Parse(parts[1]);
var point = new PointF(xCoord, yCoord);
CloudEnteringAlert.pointtocolor.Add(point);
pictureBox1.Invalidate();
}
The curItem variable contains value like that: Cloud detected at: 0.9174312 Kilometers from the coast.
I want to get only the 0.9174312 from value and set to be in the variable xCoord. The problem is that the way it is doing the parsing now i'm getting error:
Input string was not in a correct format
The index should not be zero, I guess. How can I get only the float number from the string?
And this strings formats for now are the same each time:
First part: Cloud detected at: Second part: 0.9174312 and Last part: Kilometers from the coast.
But maybe in the future I will change the string format so i need that in any place the float number will be in the middle last or start of the string to get only the float number.