How to display each individual word of a string
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi all,
How can I display each word of a string individual? I wrote a loop, but it does not work.
1 comentario
Respuestas (3)
Mischa Kim
el 5 de Feb. de 2014
Use
my_str = strsplit('This is a test');
for ii = 1:length(my_str)
display(my_str{ii});
end
0 comentarios
Azzi Abdelmalek
el 5 de Feb. de 2014
str='How to display each individual word of a string'
out=regexp(str,' ','split')
1 comentario
vikash kumar
el 26 de Dic. de 2017
Editada: vikash kumar
el 26 de Dic. de 2017
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 comentario
Walter Roberson
el 26 de Dic. de 2017
The difficulty with this is that it splits numbers like 3.14 and it splits abbreviations like "e.g."
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!