divide text into smaller blocks text by . or enter

8 views (last 30 days)
if i want to separate content of a text into smaller parts according to "new line" or "."
how to do that?
such as 2 paragraphs , 1*1 matrix:
["Today is a good day. Mom cooks breakfast for us.
But I find out only my sister is served."]
into 2*1 matrix ,divided according to being paragraphed :
["Today is a good day. Mom cooks breakfast for us.";
"But I find out only my sister is served."]
or 3*1 matrix, divided according to being paragraphed and period"." :
["Today is a good day." ;
"Mom cooks breakfast for us.";
"But I find out only my sister is served."]
thanks for helping.

Accepted Answer

Steven Lord
Steven Lord on 3 Apr 2022
S = "Today is a good day. Mom cooks breakfast for us." + newline + ...
"But I find out only my sister is served."
S =
"Today is a good day. Mom cooks breakfast for us. But I find out only my sister is served."
T = split(S, newline);
T(1)
ans = "Today is a good day. Mom cooks breakfast for us."
T(2)
ans = "But I find out only my sister is served."
  2 Comments
jingwei chen
jingwei chen on 3 Apr 2022
thanks for replying.
although it works in your way, the problem is that the text is given. the "newline" command is not what i enter. and there are hundreds of paragraphs.
jingwei chen
jingwei chen on 3 Apr 2022
Sorry. My bad. It does work. Thank you very much.

Sign in to comment.

More Answers (0)

Categories

Find more on Classical Mechanics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!