How to display each individual word of a string

6 次查看(过去 30 天)
hi all,
How can I display each word of a string individual? I wrote a loop, but it does not work.

回答(3 个)

Mischa Kim
Mischa Kim 2014-2-5
Use
my_str = strsplit('This is a test');
for ii = 1:length(my_str)
display(my_str{ii});
end

Azzi Abdelmalek
Azzi Abdelmalek 2014-2-5
str='How to display each individual word of a string'
out=regexp(str,' ','split')

vikash kumar
vikash kumar 2017-12-26
编辑:vikash kumar 2017-12-26
word_loc = find(sentence==' ' | sentence =='.');
count = size(word_loc,2);
words = cell(count,1);
prev=1;
for i=1:count
words{i}= sentence(prev:word_loc(i)-1);
prev = word_loc(i)+1;
end
  1 个评论
Walter Roberson
Walter Roberson 2017-12-26
The difficulty with this is that it splits numbers like 3.14 and it splits abbreviations like "e.g."

请先登录,再进行评论。

类别

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