How can I read a text file into a string variable and strip newlines?

I have a text file that looks like:

ABC
DEF

How can I read the file into a single-line string without newlines, in this case creating a string 'ABCDEF'?


For reading the file into a list of lines, but removing the trailing newline character from each line, see How to read a file without newlines?.

← Назад к списку