the first letter of the output string will be the first letter of the first word of the sentence.

2 次查看(过去 30 天)
Whose input is a sentence (as a string). The words of the sentence are separated by single blanks, and there is a dot at the end of the sentence. The output will be a word (as a string) created by alternatingly picking the first and last letters of the words of the sentence:
The first letter of the output string will be the first letter of the first word of the sentence. The second letter of the output string will be the last letter of the second word. The third letter will be the first letter of the third word, and so on. (You may NOT use any built-in functions except size, length, rem and mod)
Example:
If Sentence= 'The tree nut sings in no need.'
and Out = first_last_letters (Sentence)
Out will be Out='Tension'

采纳的回答

Rohith Nomula
Rohith Nomula 2020-6-9
编辑:Rohith Nomula 2020-6-9
You can split your string using a delimiter. which in your case is space
new_s = split(s,' ')
create a dummy string ans and append the required fields
Run a loop on new_s so that you can access first and last chars as follows
% for odd index string
ans = append(ans,new_s{i}(1))
% for even index string
ans = append(ans,new_s{i}(end))
Try this !
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by