JavaFX Line numbers doesn't work if there's no content on line -
I have tried to do a bit with the line number today but I have only one problem that I can not fix.
It can be calculated that if there is any material in the line, but if there is no content in it, it only says 0.
And I get text from Textaria in JavaFX. / P>
This is my simple code
GetArea (). SetOnKeyPressed (- of KeyEvent) -> {if (ke.getCode (.) Equals (KeyCode.ENTER)} {int m = GetArea (.) GetText (). Partition ("\ n"). Length; Out.println (m);}}); The method split searches for a string that matches The substrings are the regular expression, dividing the sentence at that point and leaving the matching substrings. Take a look at these examples:
-
"This is a test string. \ N And this is another." As a result ["This is a test string.", "And it is another."] And count 2.
-
"This is a test string \ N" result [[it is a test string.]] And therefore the result will be 1.
If you want to get results, you can, for example, if the last letter in the string is \ '\ n' and add 1 to line count If so, get something like this:
GetArea (). SetOnKeyPressed ((of KeyEvent)) - & gt; {If (ke.getCode (.) Equals (KeyCode.ENTER)) {string text = GetArea (). GetText (); Int m = text.split ("\ n") length; If (text .charAt (text.length () - 1) == '\ n') m ++; System.out.println (m);}});
Comments
Post a Comment