title: Using a vector to subset elements within a string vector in Julia
body: <p>I am attempting to subset a <code>Vector{String}</code> in Julia using a combination of <code>Integer</code> and <code>Vector{Integer}</code> subset values. I want to write a function that basically allows for a subsetting of <code>"asdf"[1:3]</code> with each of the three arguments <code>x[y:z]</code> to be either vectors or singletons.</p>
  
  <p>This is what I have attempted so far:</p>
  
  <pre><code>function substring(x::Array{String}, y::Integer, z::Integer)
    y = fill(y, length(x))
    z = fill(z, length(x))
    substring(x, y, z)
  end
  
  function substring(x::Vector{String}, y::Vector{Integer}, z::Integer)
    y = fill(y, length(x))
    substring(x, y, z)
  end
  
  function substring(x::Vector{String}, y::Integer, z::Vector{Integer})
    z = fill(z, length(x))
    substring(x, y, z)
  end
  
  function substring(x::Vector{String}, y::Vector{Integer}, z::Vector{Integer})
    for i = 1:length(x)
      x[i] = x[i][y[i]:min(z[i], length(x[i]))]
      # If z[i] is greater than the length of x[i] 
      # return the end of the string
    end
    x
  end
  </code></pre>
  
  <p>Attempting to use it:</p>
  
  <pre><code>v = string.('a':'z')
  x = rand(v, 100) .* rand(v, 100) .* rand(v, 100)
  
  substring(x, 1, 2)
  # or
  substring(x, 1, s)
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>MethodError: no method matching substring(::Array{String,1}, ::Int64, ::Array{Int64,1})
  Closest candidates are:
    substring(::Array{String,N}, ::Integer, !Matched::Integer) at untitled-e3b9271a972031e628a35deeeb23c4a8:2
    substring(::Array{String,1}, ::Integer, !Matched::Array{Integer,1}) at untitled-e3b9271a972031e628a35deeeb23c4a8:13
    substring(::Array{String,N}, ::Integer, !Matched::Array{Integer,N}) at untitled-e3b9271a972031e628a35deeeb23c4a8:13
    ...
   in include_string(::String, ::String, ::Int64) at eval.jl:28
   in include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N}) at eval.jl:32
   in (::Atom.##53#56{String,Int64,String})() at eval.jl:50
   in withpath(::Atom.##53#56{String,Int64,String}, ::Void) at utils.jl:30
   in withpath(::Function, ::String) at eval.jl:38
   in macro expansion at eval.jl:49 [inlined]
   in (::Atom.##52#55{Dict{String,Any}})() at task.jl:60
  </code></pre>
  
  <p>I see that there is another <a href="https://stackoverflow.com/questions/21465838/vectorabstractstring-function-parameter-wont-accept-vectorstring-input-in-j">post addressing</a> a similar error with type <a href="https://stackoverflow.com/questions/21465838/vectorabstractstring-function-parameter-wont-accept-vectorstring-input-in-j"><code>Vector{String}</code></a>. My post also ques a response to the error associated with the <code>Vector{Integer}</code>. I believe the responses to it might be helpful for others like me who find the implementation of abstract types novel and difficult.</p>