How can I parse only the float number from the string?

前端 未结 3 1202
悲&欢浪女
悲&欢浪女 2021-01-21 19:27
foreach (object item in listBox1.SelectedItems)
{
    string curItem = item.ToString();
    var parts = curItem.Split(\"{}XY=, \".ToCharArray(), StringSplitOptions.Remov         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 20:11

    Consider using regular expressions.

    var match = Regex.Match(val, @"([-+]?[0-9]*\.?[0-9]+)");
    if (match.Success)
      xCoord = Convert.ToSingle(match.Groups[1].Value);
    

提交回复
热议问题