Borrar filtros
Borrar filtros

String function

1 visualización (últimos 30 días)
Chris
Chris el 5 de Dic. de 2011
Trying to get the program to display if the letter is in the word.
And word = any word
fid = fopen('hangman.txt', 'r'); if fid < 0, error('Cannot open file.'); end CC = textscan(fid, '%s'); C = CC{1}; fclose(fid); index = ceil(rand * numel(C)); word = C{index};
first_guess=input('Enter letter'); result1=findstr(word,'first_guess')
  1 comentario
Walter Roberson
Walter Roberson el 5 de Dic. de 2011
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Dic. de 2011
result1 = ~isempty(findstr(word,first_guess));
I am taking you at your word here that you just want to display if the letter is in the word -- as opposed to displaying the positions that it occurs in the word.
Note: findstr() has been recommended against for a number of years now -- since before I started using MATLAB. strfind() is recommended in its place.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by