title: Character-returning function of unknown length
body: <p>How to use character function of where the result is of unknown length initially?</p>
  
  <p>The <code>trim()</code> function, I understand, shows that it is possible not to specify the length of returning string.</p>
  
  <p>For example:</p>
  
  <pre><code>write (*,*) trim(str)
  </code></pre>
  
  <p>will return only part of the string without trailing spaces.</p>
  
  <p>This function does not have any idea about the length of returning string before the call.</p>
  
  <p>Or <code>trim()</code> function has limitations?</p>
  
  <p>On more variant is to find original code of <code>trim()</code> function.</p>
  
  <p>I have found (<a href="https://stackoverflow.com/questions/3141709/returning-character-string-of-unknown-length-in-fortran">Returning character string of unknown length in fortran</a>) but it is not the answer to my question.</p>
  
  <p>To be sure, I want to write function, that returns string by integer number.</p>
  
  <p>Something like this:</p>
  
  <pre><code>function strByInt(myInt)
  ...
  write (strByInt,fmt) myInt; return
  end function strByInt
  
  somewhere else:
  
  write (*,*) strByInt(50) ! will write '50'
  </code></pre>