Checking how many lines catches some text

Active3 hr before
Viewed126 times

7 Answers


Stack Overflow help chat , Meta Stack Overflow ,What should be the flow ? First i need to render the component Second check if it takes 3 lines and after this change the state ?

 Pretag team - issue, fix, solve, resolve

Read line by line, and increases count + 1 each line.,This example uses BufferedReader to read line by line and increases the count.,5.1 Create a large file containing 5 million lines, 1053 characters per line, and file size of 5G.

This Files.lines is the most straightforward implementation.

public static long countLineJava8(String fileName) {

   Path path = Paths.get(fileName);

   long lines = 0;
   try {

      // much slower, this task better with sequence access
      //lines = Files.lines(path).parallel().count();

      lines = Files.lines(path).count();

   } catch (IOException e) {

   return lines;

load more v

In this example, we will learn to count the number of lines present in a file in Java.,count() - returns the number of elements in the stream,In this case, we have a file name input.txt with the following content

import java.util.Scanner;

class Main {
   public static void main(String[] args) {

      int count = 0;

      try {
         // create a new file object
         File file = new File("input.txt");

         // create an object of Scanner
         // associated with the file
         Scanner sc = new Scanner(file);

         // read each line and
         // count number of lines
         while (sc.hasNextLine()) {
         System.out.println("Total Number of Lines: " + count);

         // close scanner
      } catch (Exception e) {
load more v

You may have a requirement to count the number of lines in a field that is coming from a database. One of our SCN members had this requirement recently. ,1) change the text object (the one that you need to count the number of lines) to use a fixed width font…apologies to those that don’t care for fixed width fonts but this is a requirement,Wouldn't it be a lot easier just to split the whole string into an array, then count the number of items in the array - I make that about 3 lines of code!

 Pretag team - issue, fix, solve, resolve

There must be a way to see how many characters can a line hold in UI/Text, then we can split the words and count the length of every word and see by adding which word the line length goes over that maximum length. then we can consider it one line.,Text.cachedTextGenerator has the info you need. It won't show correct line splitting until the next frame, but you can force it to update early by calling Canvas.ForceUpdateCanvases().,How can I get the lines of Text that is showing in the game, not in the inspector window, as u see in the picture:

alt text

 myText = GetComponent<Text>();    
 string[] lines = myText.text.Split('\n');
  //real output :
  //New Text
  //What I expect:

load more v

C - Mathematical Functions,Sanfoundry Global Education & Learning Series – 1000 C Programs., //Count whenever new line is encountered

load more v

 Pretag team - issue, fix, solve, resolve

Other "checking-lines" queries related to "Checking how many lines catches some text"