# Help with string mapping from input

**URL:** <https://discourse.julialang.org/t/help-with-string-mapping-from-input/16752>\
**Category:** New to Julia\
**Created:** [October 24, 2018, 6:29pm UTC](https://discourse.julialang.org/t/help-with-string-mapping-from-input/16752 "2018-10-24T18:29:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 27, 2018, 8:26am UTC](https://discourse.julialang.org/t/help-with-string-mapping-from-input/16752/2 "2018-10-27T08:26:44Z")

</div>

You could define something crude as

```julia
parsefield(T::Type{<:Real}, str::AbstractString) = parse(T, str)
parsefield(::Type{T}, str::T) where T <: AbstractString = str
parsefield(::Type{T}, str::AbstractString) where T <: AbstractString = T(str)

schemas = Dict(["ABC" => (a = Int64, b = Int64, c = Int64, animal = String, put = String)])

function parsewithschema(row, schemas)
    key, fields = split(row, '=')
    schema = schemas[key]
    NamedTuple{keys(schema)}(map(parsefield, schemas[key], split(fields, ',')))
end

```

then

```julia
julia> parsewithschema(inputtext[1], schemas)
(a = 1, b = 2, c = 3, animal = "cats", put = "dogs")

```

Would need a bit of refinement, whitespace stripping, and validation for real-life applications, but you get the idea. You can then interface into [Tables.jl](https://github.com/JuliaData/Tables.jl).

Alternatively, leverage the row-reading functionality from one of the CSV reading libraries.

**EDIT** : Try using Parsers.jl for the fields, as described [here](https://discourse.julialang.org/t/fastest-way-to-parse-a-string-of-numbers/16720/4).

---

_[View the full topic](https://discourse.julialang.org/t/help-with-string-mapping-from-input/16752)._
