Convert string with commas to float

前端 未结 9 2161
走了就别回头了
走了就别回头了 2021-02-19 18:58

Is there a built-in Delphi function which would convert a string such as \'3,232.00\' to float? StrToFloat raises an exception because of the comma. Or is the only way to stri

9条回答
  •  长情又很酷
    2021-02-19 19:32

    using lemda Expression to convert string comma seprated to float array

    public static float[] ToFloatArrayUsingLemda()
        {
            string pcords="200.812, 551.154, 232.145, 482.318, 272.497, 511.752";
            float[] spiltfloat = new float[pcords.Split(',').Length];
    
            string[] str = pcords.Split(',').Select(x => x.Trim()).ToArray();
    
            spiltfloat = Array.ConvertAll(str, float.Parse);
            return spiltfloat;
        }
    

提交回复
热议问题