The other functions that also received Substring did not show error:
This runs:
type or paste code here
```function insertField!(db::Dict,params::SubString{String})
typeof(params)
arr=split(params," ",limit=3)
println(typeof(arr))
println(length(arr))
A substring is like a view into a string, i.e., references into an existing string instead of allocating a new data structure. Many functions for splitting, matching etc on strings return substrings. Here is an example:
Note that a SubString is not a String, i.e., a function with signature op::String will not work as expected:
julia> fun(op::String) = length(op)
fun (generic function with 1 method)
julia> fun(txt)
8
julia> fun(sub)
ERROR: MethodError: no method matching fun(::SubString{String})
If in doubt, leave out the type signature all together (would suggest that for beginners anyways) or use AbstractString instead which will match all of its subtypes:
Then arr[2] extracts one element from the vector which gives you a SubString{String}. When you send that single element to insertField! it complains because it requires a whole vector, not a single element.
The error says that insertField! expected a vector in its second argument (as per your type signature Vector{SubString{String}}), but was called with a SubString{String}, i.e., as single element of such a vector. Have not checked if this function actually needs to get passed a vector – but as split is called on params it most likely does not.
In any case, such a specific type signature usually restricts code unnecessarily. Consider AbstractVector{<:AbstractString} instead.