How to extract multiple floats from a string of floats in C#

1 Answer

0 votes
using System;

public class ExtractFloatsFromString_CSharp {
    public static void Main(string[] args) {
        string str = "2.809 -36.91 21.487 -493.808 5034.7001";
        float[] floats = new float[5];

        var tokens = str.Split(' ');
        int i = 0;

        foreach (var token in tokens) {
            float f = float.Parse(token);
            Console.WriteLine(f);
            floats[i++] = f;
        }
    }
}


    
/*
run:
    
2.809
-36.91
21.487
-493.808
5034.7
    
*/

 



answered Jul 28, 2024 by avibootz

Related questions

1 answer 64 views
1 answer 71 views
1 answer 77 views
1 answer 76 views
1 answer 81 views
1 answer 68 views
1 answer 89 views
...