I have a text file in which I specify some Makie plot labels and some of those labels have newline characters in them. I’ve attempted a few different ways to read that text file so that the two character “\n” gets translated into the single ‘\n’ for Makie but none of them have worked I may end up manipulating the vector of UInt8 to parse escaped newline characters, but I am hoping someone knows of an easier way.
I’ve tried the following:
function mweesc()
# write temp file
fn = "temp.txt"
str = """
this\\nis
a test of escaped\\nnewlines
"""
write(fn, str)
# read temp file
io = IOBuffer()
open(fn, "r") do f
nLine = 0
while !eof(f)
line = readline(f, keep=true)
nLine += 1
println("line $nLine:")
print("$line")
println("line[5] = '$(line[5])'")
str = string("$line")
print("$str")
println("str[5] = '$(str[5])'")
# print(io,"$line")
# v = take!(io)
# println("v[5] = $(v[5])")
# str = String(v)
end # while
end # open
end
and the output is:
julia> mweesc()
line 1:
this\nis
line[5] = '\'
this\nis
str[5] = '\'
line 2:
a test of escaped\nnewlines
line[5] = 's'
a test of escaped\nnewlines
str[5] = 's'
but I would like str[5] to be ‘\n’ instead of ‘\’.