0

I make some Letter program by using Unity.

For Text Input, I use TMP_Inputfield, and I need to get the line of text, because I want to make this programs respond well when I press the Enter key.

When I set the line Limit as 5, and Line Type as Multi Line NewLine, If I enter the fifth line and press the enter key, the cursor moves to the next line.

In this case, I want to deactivate TMP_Inputfield or activate next TMP_Inputfield.

In the TMP_Inputfield, Only the Line_limit could be set up, but cannot get the lines of text.

In order to deal with such cases, I want to get the lines of text. how can I get this?

Here is my TMP_Inputfield settings.

aybe
  • 15,516
  • 9
  • 57
  • 105

1 Answers1

0

It's a bit unclear what exactly you are asking.

You get/set this via lineLimit .. and for getting the amount of lines in a string you could probably do

using System.Linq;

...

var lineCount = inputField.text.Count(c => c == '\n') + 1;

or without Linq

var lineCount = inputField.text.Split('\n').Length;
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • derHugo, Thanks. But if text Length is too long, text would be go to next line automatically without '\n'. In this case, how do we check the number of lines? – Napol-Napol Feb 15 '22 at 03:22