You can also use chomp() which is specific to newlines (strip() removes all whitespace) Base.chomp(string)
Remove a trailing newline from a string julia> a = "asd " "asd " julia> chomp(a) "asd " julia> strip(a) "asd" On Wednesday, June 17, 2015 at 4:41:45 AM UTC-5, René Donner wrote: > > Hi, > > you can use strip() for that. This and some other very handy functions > (e.g. lstrip / rstrip) are listed in > http://docs.julialang.org/en/release-0.3/stdlib/strings/?highlight=strip#strings > > > cheers, > > rene > > > > > Am 17.06.2015 um 11:38 schrieb Paul Analyst <[email protected] > <javascript:>>: > > > Is another way [1:end-1] to lost "\n" on the end of line? > > > > julia> readline(open("temp.txt"))[1:end] > > "1\n" > > > > julia> readline(open("temp.txt"))[1:end-1] > > "1" > > Paul > > > > W dniu 2015-06-17 o 11:33, Paul Analyst pisze: > >> Ok, sorry, i don`t see 1 line:) > >> Base.readline(s, i::Int) = (for (j,line) in enumerate(eachline(s)); if > j==i; return line; end; end; error("not enough lines")) > >> > >> Is oK ,big thx > >> Paul > >> > >> W dniu 2015-06-17 o 11:27, Paul Analyst pisze: > >>> Unfrtunatly can`t run, (in Julia 3.6 the same) > >>> _ > >>> _ _ _(_)_ | A fresh approach to technical computing > >>> (_) | (_) (_) | Documentation: http://docs.julialang.org > >>> _ _ _| |_ __ _ | Type "help()" for help. > >>> | | | | | | |/ _` | | > >>> | | |_| | | | (_| | | Version 0.4.0-dev+2847 (2015-01-21 18:34 > UTC) > >>> _/ |\__'_|_|_|\__'_| | Commit fc61385 (146 days old master) > >>> |__/ | x86_64-w64-mingw32 > >>> > >>> > >>> julia> f = open("temp.txt","w") > >>> IOStream(<file temp.txt>) > >>> > >>> julia> for i in 1:20 write(f, "$i\n") end > >>> > >>> julia> close(f) > >>> > >>> > >>> julia> readline(open("temp.txt"), 15) > >>> ERROR: MethodError: `readline` has no method matching > readline(::IOStream, ::Int64)SYSTEM: show(lasterr) caused an > >>> error > >>> julia> readline(open("temp.txt")) > >>> "1\n" > >>> > >>> julia> readline(open("temp.txt")) > >>> "1\n" > >>> > >>> julia> readlines(open("temp.txt")) > >>> 20-element Array{Union(ASCIIString,UTF8String),1}: > >>> "1\n" > >>> "2\n" > >>> "3\n" > >>> "4\n" > >>> "5\n" > >>> "6\n" > >>> "7\n" > >>> "8\n" > >>> "9\n" > >>> "10\n" > >>> "11\n" > >>> "12\n" > >>> "13\n" > >>> "14\n" > >>> "15\n" > >>> "16\n" > >>> "17\n" > >>> "18\n" > >>> "19\n" > >>> "20\n" > >>> Paul > >>> W dniu 2015-06-16 o 19:49, Tom Breloff pisze: > >>>> You could create your own: > >>>> > >>>> julia> Base.readline(s, i::Int) = (for (j,line) in > enumerate(eachline(s)); if j==i; return line; end; end; error("not enough > lines")) > >>>> readline (generic function with 4 methods) > >>>> > >>>> julia> f = open("/tmp/tmp.txt", "w") > >>>> IOStream(<file /tmp/tmp.txt>) > >>>> > >>>> julia> for i in 1:20 write(f, "$i\n") end > >>>> > >>>> julia> close(f) > >>>> > >>>> julia> readline(open("/tmp/tmp.txt"), 15) > >>>> "15\n" > >>>> > >>>> julia> readline(open("/tmp/tmp.txt"), 25) > >>>> ERROR: not enough lines > >>>> in readline at none:1 > >>>> > >>>> > >>>> > >>>> > >>>> On Tuesday, June 16, 2015 at 12:17:28 PM UTC-4, paul analyst wrote: > >>>> If o is stream > >>>> o=open(file) > >>>> > >>>> how to read any line ?e.g. 15 > >>>> > >>>> julia> readline(o,15) > >>>> ERROR: MethodError: `readline` has no method matching > readline(::IOStream, ::Int64)SYSTEM: show(lasterr) caused > >>>> error > >>>> > >>>> Paul > >>> > >> > > > >
