Bugfix for datafiles with spaces at the end

Basically it was creating some issues because valuating the related
string generated an array with an undefined element. Now I put some
check both on the readdatafromfile and writedatatofile