# How to parse the string entries read from a file into their struct / types?

**URL:** <https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909>\
**Category:** General Usage\
**Created:** [December 5, 2019, 2:24pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909 "2019-12-05T14:24:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [December 5, 2019, 2:24pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/1 "2019-12-05T14:24:08Z")

</div>

I was reading a text file, which has the following columns: startTimes, startLocs, planedRouteNds, edgesDists, edgesTravelTimes, dists, durationTimes, and eventCtgrs. Each one of them has a different type. For example, startTimes is of type Float64, startLocs is of type LLA, planedRouteNds is of type Array{LLA,1}, edgesDists is of type Array{Float64,1}, edgesTravelTimes is of type Array{Float64,1}, dists is of type Float64, durationTimes is of type Float64 and eventCtgrs is of type EventCtgrs. I read the whole file by readlines, and then process the obtained array line by line. The tricky part is that, readlines will read the whole file into an array of lines, with each line a string. I can split the string into separate cells, but the question is, how to parse the string cells into its corresponding typed entries? Or is there any better way to do this? Any comments are greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [December 5, 2019, 2:28pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/2 "2019-12-05T14:28:20Z")

</div>

Could you give a small example of how such a file would look like? I think that would help the answers.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [December 5, 2019, 2:38pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/3 "2019-12-05T14:38:25Z")

</div>

startTime,startLoc,planedRouteNds,edgesDists,edgesTravelTimes,dist,durationTime,eventCtgr  
0.0;LLA(66.54406322195405, 23.143566102684176, 0.0);Any;Any;Any;0;-1.0;vehicleGetReady;  
71.32207701198374;LLA(66.50569110246629, 12.73100700341307, 0.0);LLA[LLA(66.0685394, 14.8741299, 0.0), LLA(66.0497297, 14.8968747, -1.862645149230957e-9),…

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [December 5, 2019, 2:42pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/4 "2019-12-05T14:42:44Z")

</div>

I’m sorry, I can’t quite make out what I’m looking at. Is that one row? Could possibly you format and annotate the example?

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [December 7, 2019, 12:33pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/5 "2019-12-07T12:33:17Z")

</div>

header is as the following:  
startTime,startLoc,planedRouteNds,edgesDists,edgesTravelTimes,dist,durationTime,eventCtgr  
First line:  
0.0;LLA(66.54406322195405, 23.143566102684176, 0.0);Any;Any;Any;0;-1.0;vehicleGetReady;  
part of second line:  
71.32207701198374;LLA(66.50569110246629, 12.73100700341307, 0.0);LLA[LLA(66.0685394, 14.8741299, 0.0), LLA(66.0497297, 14.8968747, -1.862645149230957e-9),…

---

<div class="post-metadata">

**Author:** ![Karajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karajan/32/8545_2.png) [@Karajan](https://discourse.julialang.org/u/Karajan)\
**Post date:** [December 9, 2019, 2:46pm UTC](https://discourse.julialang.org/t/how-to-parse-the-string-entries-read-from-a-file-into-their-struct-types/31909/6 "2019-12-09T14:46:03Z")

</div>

So… is this all valid Julia code? If so, how did you come to this file? Maybe there is a way to do this more elegantly.
