Storing Strings using For Loops

I would do it this way:

julia> a
"GAMG:  Solving for p, Initial residual = 1, Final residual = 0.0580078, No Iterations 7"

julia> m = match(r".*Initial residual =\s(.*),.*Final residual =\s(.*),", a);

julia> parse.(Float64, m.captures)
2-element Vector{Float64}:
 1.0
 0.0580078

guess work:

const f = eachline("Cruciform/Post-Processing/hellothere.txt")
let storage = Float64[]
for l in f
    if occursin("Solving for p", l)
        m = match(r".*Initial residual =\s(.*),.*Final residual =\s(.*),", l)
        init, final = parse.(Float64, m.captures)
        push!(storage, init)
    end
end

display(storage)
end
2 Likes