scala - Reading and filtering a file into a string -
i new scala , need read contents of text file string while removing lines @ same time. lines removed can identified substring match. come following solution, works, problem newlines removed:
val fileasfilteredstring = io.source.fromfile("file.txt").getlines.filter(s => !(s contains "filter these")).mkstring;
how can keep newlines?
add parameters mkstring
:
val fileasfilteredstring = io.source.fromfile("file.txt").getlines .filter(s => !(s contains "filter these")).mkstring("\n")
Comments
Post a Comment