best way to convert string array of floats to a float array

Brad Anderson eco at gnuk.net
Mon Jul 23 19:05:17 PDT 2012


On Tuesday, 24 July 2012 at 02:03:40 UTC, Stephen Jones wrote:
> When it comes to reading float data from a text file into a 
> float array is there a better option than reading the data into 
> a string array and then stepping though the array and 
> converting the values into a float array:
>
> string[] textData=read text data;
> float[] f;
>
> foreach(string s; textData){
>     f~=to!(float)(s);
> }

auto flist = textDataRange.map!(a => a.to!float).array();


More information about the Digitalmars-d-learn mailing list