function dvec = s_to_isbn_digits ( s, n )

%*****************************************************************************80
%
%% S_TO_ISBN_DIGITS extracts N ISBN digits from a string.
%
%  Discussion:
%
%    The string may include spaces, letters, and dashes, but only the
%    digits '0' through '9' and 'X' will be extracted.
%
%  Example:
%
%    S  => 34E9X-70.6
%    N  => 5
%    D <=  (/ 3, 4, 9, 10, 7 /)
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    16 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_ISBN_DIGITS - Fatal error!\n' );
      fprintf ( 1, '  Could not read enough data from string.\n' );
      error ( 'S_TO_ISBN_DIGITS - Fatal error!' );
    end

    c = s(s_pos);

    if ( ch_is_isbn_digit ( c ) )
      d_pos = d_pos + 1;
      dvec(d_pos) = isbn_digit_to_i4 ( c );
    end

  end

  return
end
