Let's get some text from Charles Dicken's Oliver Twist.
Define:
strCD = "Although I am not disposed to maintain that the being born \
in a workhouse,is in itself the most fortunate and enviable \
circumstance that can possibly befall a human being,I do mean to say \
that in this particular instance,it was the best thing for Oliver \
Twist that could by possibility have occurred.The fact is,that there \
was considerable difficulty in inducing Oliver to take upon himself \
the office of respiration,--a troublesome practice,but one which \
custom has rendered necessary to our easy existence;and for some time \
he lay gasping on a little flock mattress,rather unequally poised \
between this world and the next:the balance being decidedly in favour \
of the latter.Now,if,during this brief period,Oliver had been \
surrounded by careful grandmothers,anxious aunts,experienced \
nurses,and doctors of profound wisdom,he would most inevitably and \
indubitably have been killed in no time.There being nobody \
by,however,but a pauper old woman,who was rendered rather misty by an \
unwonted allowance of beer;and a parish surgeon who did such matters \
by contract;Oliver and Nature fought out the point between them.The \
result was,that,after a few struggles,Oliver breathed,sneezed,and \
proceeded to advertise to the inmates of the workhouse the fact of a \
new burden having been imposed upon the parish,by setting up as loud \
a cry as could reasonably have been expected from a male infant who \
had not been possessed of that very useful appendage,a voice,for a \
much longer space of time than three minutes and a quarter. As Oliver \
gave this first proof of the free and proper action of his lungs, the \
patchwork coverlet which was carelessly flung over the iron bedstead, \
rustled; the pale face of a young woman was raised feebly from the \
pillow; and a faint voice imperfectly articulated the words, 'Let me \
see the child, and die. The surgeon had been sitting with his face \
turned towards the fire: giving the palms of his hands a warm and a \
rub alternately. As the young woman spoke, he rose, and advancing to \
the bed's head, said, with more kindness than might have been \
expected of him:
'Oh, you must not talk about dying yet.'
'Lor bless her dear heart, no!' interposed the nurse, hastily
depositing in her pocket a green glass bottle, the contents of which
she had been tasting in a corner with evident satisfaction.
'Lor bless her dear heart, when she has lived as long as I have, sir,
and had thirteen children of her own, and all on 'em dead except two,
and them in the wurkus with me, she'll know better than to take on in
that way, bless her dear heart! Think what it is to be a mother,
there's a dear young lamb do.'
Apparently this consolatory perspective of a mother's prospects
failed in producing its due effect. The patient shook her head, and
stretched out her hand towards the child.
The surgeon deposited it in her arms. She imprinted her cold white
lips passionately on its forehead; passed her hands over her face;
gazed wildly round; shuddered; fell back--and died. They chafed her
breast, hands, and temples; but the blood had stopped forever. They
talked of hope and comfort. They had been strangers too long.
'It's all over, Mrs. Thingummy!' said the surgeon at last.
'Ah, poor dear, so it is!' said the nurse, picking up the cork of the
green bottle, which had fallen out on the pillow, as she stooped to
take up the child. 'Poor dear!'
'You needn't mind sending up to me, if the child cries, nurse,' said
the surgeon, putting on his gloves with great deliberation. 'It's
very likely it will be troublesome. Give it a little gruel if it
is.' He put on his hat, and, pausing by the bed-side on his way to
the door, added, 'She was a good-looking girl, too; where did she
come from?'
'She was brought here last night,' replied the old woman, 'by the
overseer's order. She was found lying in the street. She had walked
some distance, for her shoes were worn to pieces; but where she came
from, or where she was going to, nobody knows.'";
Split into sentences:
slist = TextSentences[strCD]
These are the number of characters in the sentences.
StringLength /@ slist
{300, 376, 216, 222, 402, 309, 127, 130, 40, 190, 241, 63, 99, 73,
37, 147, 78, 32, 33, 58, 156, 12, 128, 43, 173, 83, 34, 131}
Define: (a function that I used in a recent answer.
cSplit3[inList_List, f_Function] := Module[{rem = inList, i},
Reap[
While[rem != {},
i = 1;
While[i <= Length@rem && f@Take[rem, i],
i++;
];
i--;
Sow@rem[[1 ;; i]];
rem = Drop[rem, i];
]
][[2, 1]]
]
Usage: (Here I have chosen max count of 600)
(chunks = cSplit3[slist, Total@StringLength@# < 600 &]) // Column
StringLength /@ chunks
{{300}, {376, 216}, {222}, {402}, {309, 127, 130}, {40, 190, 241,
63}, {99, 73, 37, 147, 78, 32, 33, 58}, {156, 12, 128, 43, 173,
83}, {34, 131}}
Output: (* see chunks *)
Original answer
Manipulate[
StringJoin @@@ (Partition[Characters@string, UpTo[n]]) // TableForm
, {{n, 10}, 10, 50, 1}
]
TextSentences[string]would also accomplish the same asTextCases[string, "Sentence"]. – MarcoB Jun 16 '22 at 15:43TextSentencesis robust.StringSplitis not intelligent. Consider:StringSplit["Moon is 2.4 million miles away. Second sentence. Third \ sentence.", "."]– Syed Jun 16 '22 at 16:08