Is it possible to reset a new-line character when read txt file in julia?

In perl, if you want reset new-line character, you can use
$/="new_character". So is it possible to reset a new-line character when read txt file in julia ?


I don’t understand what this means.

If you want to remove trailing newlines from a string, use chomp.

I don’t think that you can set a custom separator in a global way like you do in Perl. However, what you can do is read your file using readuntil instead of readline if you want to be able to specify a delimiter for the chunk that you want to read.

Here is an example taken from the documentation of readuntil, where the character L is used as a delimiter.

  julia> open("my_file.txt", "w") do io
             write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
  julia> readuntil("my_file.txt", 'L')
1 Like

sorry, I should use more accurate word like delimiter as @ffevotte

thanks~ I should use delimiter. because don’t know the how many lines by new delimiter, so how to loop the all lines by new delimiter?

I use this to loop

open("tmp") do file
	while ! eof(file)
		line = readuntil(file, ">")
		line = chomp(line)
		println("line is ",line)

Something like that, I don’t think you need chomp unless there is a newline to remove. Also, I would specify readuntil(...; keep = false) to be explicit, although that is the default.