title: Spark Scala to count length in dataframe fields
body: <p>New to Scala.</p>
  
  <p>I have created a substring function in scala which requires "pos" and "len", I want pos to be hardcoded, however for the length it should count it from the dataframe. How would I go about doing this?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>val A = DF.select(col("example_ref"), substring(col("example_ref"),11, 21))
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>So added this code:</p>
  
  <pre><code>val A = DF.select($"example_ref",substring($"example_ref",11,length($"example_ref")))
  </code></pre>
  
  <p>However I get the following errors:</p>
  
  <pre><code>Type Mismatch, expected: String, actual: Column
  Type Mismatch, expected: Int, actual: Column
  </code></pre>