package edu.vt.marian.common; import java.io.*; import java.net.*; import java.util.*; /** Class name: LinedString Class description: used to count the number of "\n" in s string Author: Jianxin Zhao Finished time: ????, 1998 Known bugs: none Platform: jdk1.1.5 under UNIX */ public class LinedString { /** just for testing */ Debug debug; /** this constructor will create a LinedString object */ public LinedString(Debug debug) { this.debug = debug; } /** this method will return number of "\n"s contained in the string */ public static int count_lines(String s) { if (s == null) { return 0; } // not null string int length = s.length(); int number_lines = 1; int i; for (i = 0; i < length; i++) { if (s.charAt(i) == '\n') { number_lines++; } } return number_lines; } }