function dvec = s_to_digits ( s, n )

%*****************************************************************************80
%
%% s_to_digits() extracts N digits from a string.
%
%  Discussion:
%
%    The string may include spaces, letters, and dashes, but only the
%    digits 0 through 9 will be extracted.
%
%  Example:
%
%    S  => 34E94-70.6
%    N  => 5
%    D <=  (/ 3, 4, 9, 4, 7 /)
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    09 September 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string S, the string.
%
%    integer N, the number of digits to extract.
%
%  Output:
%
%    integer DVEC(N), the extracted digits.
%
  s_len = length ( s );

  s_pos = 0;
  d_pos = 0;

  dvec = zeros ( n, 1 );

  while ( d_pos < n )

    s_pos = s_pos + 1;

    if ( s_len < s_pos )
      fprintf ( 1, '\n' );
      fprintf ( 1, 's_to_digits(): Fatal error!\n' );
      fprintf ( 1, '  Could not read enough data from string.\n' );
      error ( 's_to_digits(): Fatal error!' );
    end

    c = s(s_pos);

    if ( '0' <= c && c <= '9' )
      d_pos = d_pos + 1;
      d = c - '0';
      dvec(d_pos) = d;
    end

  end

  return
end
