String manipulation with printing of characters

21 ビュー (過去 30 日間)
Liz
Liz 2020 年 11 月 17 日
回答済み: Walter Roberson 2020 年 11 月 17 日
The question is:
Write a script that will prompt the user to enter a word, and then print the first character in the word. For example, the output might look like this:
>> Enter a word: howdy
The word howdy starts with the letter ‘h’
How do you print the first character? I can do the:
>> word = input('Enter a word: ','s')
I do not know to display the first character.

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 17 日
hint
fprintf('%s : ''%s''\n', t, t(1))

その他の回答 (1 件)

NAVNEET NAYAN
NAVNEET NAYAN 2020 年 11 月 17 日
I think the following code should work
t=input('Enter a word: ', 's');
disp(t(1));
  2 件のコメント
Liz
Liz 2020 年 11 月 17 日
Yes I did try that before, but the question wants you to print the first letter with the quote 'The word howdy starts with the letter 'h'. I thought about maybe using fprintf, but couldn't think how to do that.
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 11 月 17 日
Try this and see whether it solves the purpose or not. I think it should work
t=input('Enter a word: ', 's');
char(t(1));

サインインしてコメントする。

カテゴリ

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