フィルターのクリア

display help

1 回表示 (過去 30 日間)
Chris
Chris 2011 年 12 月 5 日
I'm trying to create a program that plays a hangman game. So, how would I go about replacing the letters in the word with asterisks. I want the user to see the asterisks instead of the letters so they can see how many letters are in the word.

採用された回答

Jan
Jan 2011 年 12 月 5 日
You need two strings: The original string of all the letters, and a 2nd one, which consists of stars initially. If the users selectes a letter, the corresponding elements of the star-string are replaced by this letter.
original = 'hello world';
stars = original;
stars(~isspace(stars)) = '*';
selected = 'l'; % lower-case El
stars(original == selected) = selected;
BTW. this is a nice homework. You can learn the Matlab basics as logicla indexing and assignment of scalars to arrays as well as the string handling.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by