String manipulation with printing of characters
27 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
更多回答(1 个)
NAVNEET NAYAN
2020-11-17
I think the following code should work
t=input('Enter a word: ', 's');
disp(t(1));
2 个评论
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 Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!