I am reading in data in the following format:
{ok,Volts} = file:open("voltage1.dat",read).
In the ‘voltage.dat’ file there is a single value which is converted into
the string
" 9.9944639227844667e-001\n". This should be assigned to the Volts variable.
In order to use the string_to_float function later I need to strip away the spaces
and remove the \n delimiter.
I have explored using string:strip, string:substr and re:replace library functions.
I am using the variable Volts as the input string when I try each of these, e.g:
string:substr(Volts,3,18).
This does not work. I think it is because of the way that I am
inputting the Volts variable.
Can anyone put me right?
will just open the file; Volts is a file descriptor, not the file’s contents. In order to read the file you can use functions from the io module. Besides reading the whole file and then interpreting you can use fread/3:
If you don’t want/can do that (maybe your file has a more complex format) remember that string are lists, therefore you can use
filter/2and other list functions