# Put sentences in Label Caption

**URL:** <https://forum.castle-engine.io/t/put-sentences-in-label-caption/277>\
**Category:** Uncategorized\
**Created:** [December 31, 2020, 3:22pm UTC](https://forum.castle-engine.io/t/put-sentences-in-label-caption/277 "2020-12-31T15:22:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carring](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/carring/32/1950_2.png) [@Carring](https://forum.castle-engine.io/u/Carring)\
**Post date:** [December 31, 2020, 3:22pm UTC](https://forum.castle-engine.io/t/put-sentences-in-label-caption/277/1 "2020-12-31T15:22:19Z")

</div>

Hi!

I want to input sentences as Label Caption on run time.  
The idea is to break the sentences in several lines with LineEnding.

This is what I have, but obviously not what it should be.  
I want the lines to be of a certain length instead of 10 words per line.  
Also the maximum C variable for looping should be not higher than the number of words.

ReadString := ‘Welcome sir, I hope you had a pleasant journey. I will guide you to the base from here but feel free to ask me to guide you around the island also.’;

ReadString:= MidStr(ReadString, 0, Length(ReadString));

for C := 1 to 500 do  
begin  
EndPos := PosEx(’ ', ReadString, StartPos);  
Word[C] := MidStr(ReadString, StartPos, EndPos - StartPos);  
StartPos := EndPos + 1;  
end;

TalkTextLabel.Caption :=  
Word[1] + Word[2] + Word[3] + Word[4] + Word[5] + Word[6] + Word[7] + Word[8] + Word[9] + Word[10] + LineEnding +  
Word[11] + Word[12] + Word[13] + Word[14] + Word[15] + Word[16] + Word[17] + Word[18] + Word[19] + Word[20] + LineEnding +  
Word[21] + Word[22] + Word[23] + Word[24] + Word[25] + Word[26] + Word[27] + Word[28] + Word[29] + Word[30] + LineEnding +  
Word[31] + Word[32] + Word[33] + Word[34] + Word[35] + Word[36] + Word[37] + Word[38] + Word[39] + Word[40] + LineEnding +  
Word[41] + Word[42] + Word[43] + Word[44] + Word[45] + Word[46] + Word[47] + Word[48] + Word[49] + Word[50] + LineEnding;

---

<div class="post-metadata">

**Author:** ![eugeneloza](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/eugeneloza/32/12_2.png) [@eugeneloza](https://forum.castle-engine.io/u/eugeneloza)\
**Post date:** [December 31, 2020, 4:05pm UTC](https://forum.castle-engine.io/t/put-sentences-in-label-caption/277/2 "2020-12-31T16:05:55Z")

</div>

@Carring Hi and welcome! 🙂

I’m not 100% sure if I understood your question correctly.

`TCastleLabel` automatically splits the text into lines, just specify a proper `MaxWidth` [https://castle-engine.io/apidoc-unstable/html/CastleControls.TCastleLabel.html#MaxWidth](https://castle-engine.io/apidoc-unstable/html/CastleControls.TCastleLabel.html#MaxWidth) - it’ll automatically break the line at words.

If for some reason you want to do that manually try `SplitString` function [https://castle-engine.io/apidoc-unstable/html/CastleStringUtils.html#SplitString](https://castle-engine.io/apidoc-unstable/html/CastleStringUtils.html#SplitString) to split the sentence into words. Then you can use `TCastleFont.TextWidth` [https://castle-engine.io/apidoc-unstable/html/CastleFonts.TCastleFont.html#TextWidth](https://castle-engine.io/apidoc-unstable/html/CastleFonts.TCastleFont.html#TextWidth) to determine the length of every word or some sentence fragments (e.g. to see if it exceeds the line width or not).

---

<div class="post-metadata">

**Author:** ![Carring](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/carring/32/1950_2.png) [@Carring](https://forum.castle-engine.io/u/Carring)\
**Post date:** [December 31, 2020, 4:39pm UTC](https://forum.castle-engine.io/t/put-sentences-in-label-caption/277/3 "2020-12-31T16:39:04Z")

</div>

Thanks! That was more easy than I thought. I did not know the words were automatically split with maxwidth so I was looking for the spaces between them.
