How to get a specific line from an autowrapped text?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By henriquelalves
:warning: Old Version Published before Godot 3 was released.

I’m wondering how I would be able to get a specific line from a text in a Label with the Autowrapped feature on. The “\n” (new line) character won’t appear in the String variable stored on the label (as it is autowrapping, I guess the text editing goes on the backend), so I wouldn’t be able to just parse the text and reach the line that I want.

I was trying to create a way to do this, because in the project that I’m currently into, I’ll need to delete the “skipped lines” (the lines in the beginning of the text that won’t appear) from the label text; but there is no way to do it without a brute-force iteration on each character, searching for the one that actually separates the skipped line from the lines that are currently being printed.

The only solution I thought would be using a threshold (e.g. there is the double of skipped lines than lines that are being printed by the label), and deleting the first 30% of text; I would ALMOST be sure that the first 30% of text wouldn’t happen to have one the lines that are being printed by the label, but this almost is killing me, haha.

(Using a maximum amount of characters instead of lines wouldn’t work either, as characters have possibly different sizes, which would affect how many characters are in each line.)

:bust_in_silhouette: Reply From: henriquelalves

I found a solution, although it isn’t exactly what I was looking for.

What I did in the Text-Engine I built (GitHub - henriquelalves/GodotTIE: A simple Text Interface Engine to control text output (like in a RPG dialogue) for Godot.) was to use the “autowrapped” feature of the Label, only to test if words would have to be clipped (an extra line would have to be added). If they have to, that I would edit the text manually to add the “\n” before the word.

I don’t know how this solution works in a performance-heavy test, but all the tests that I did using it worked nicely.