V
V
Volgarastraport2016-03-11 17:02:25
C++ / C#
Volgarastraport, 2016-03-11 17:02:25

How to split long text into lines in C#?

It is necessary to divide the text into lines so that each has no more than a given number of characters, but at the same time the division (hyphenation) does not fall on a word (the word is not cut off).
Maybe there is a ready-made snippet?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alec Onim, 2016-03-11
@Caitiff_One

You can, as suggested by Vladimir Martyanov :)
There is still an option - split by spaces and collect lines in turn, i.e. split by spaces - collect a string from the resulting pieces (and spaces, of course), along the way checking whether you exceed the allowed number of characters before adding. If you exceed - then this line is finished, form a new one :)

V
Vladimir Martyanov, 2016-03-11
@vilgeforce

If you need no more than N characters in a string, look for a back space starting from a position that is a multiple of N. There will be a gap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question