lines

counting the number of lines in a text file (java)

十年热恋 提交于 2019-12-06 07:49:44
Below is how i count the number of lines in a text file. Just wondering is there any other methods of doing this? while(inputFile.hasNext()) { a++; inputFile.nextLine(); } inputFile.close(); I'm trying to input data into an array, i don't want to read the text file twice. any help/suggestions is appreciated. thanks Edgar H If you just want to add the data to an array, then I append the new values to an array. If the amount of data you are reading isn't large and you don't need to do it often that should be fine. I use something like this, as given in this answer: Reading a plain text file in

Android Development: Count EditText Lines on textChanged?

霸气de小男生 提交于 2019-12-06 06:30:48
问题 How can I count the number of lines in an EditText? Basically in my app I have line numbers and I wanted to make them update on textchange (I already have the textchangelistener set up). Is this possible? :( Thanks, Alex! 回答1: Lines can be differents: Visible lines: Wrapped text count as a new line... List item: Only lines with \r, \n, \r\n First case (the easiest): int nbLines = editText.getLineCount(); Second case: int nbLines = 0; StringReader sr = new StringReader(editText.getText()

Remove Duplicate Lines from Text using Java

随声附和 提交于 2019-12-06 05:04:07
问题 I was wondering if anyone has logic in java that removes duplicate lines while maintaining the lines order. I would prefer no regex solution. 回答1: public class UniqueLineReader extends BufferedReader { Set<String> lines = new HashSet<String>(); public UniqueLineReader(Reader arg0) { super(arg0); } @Override public String readLine() throws IOException { String uniqueLine; if (lines.add(uniqueLine = super.readLine())) return uniqueLine; return ""; } //for testing.. public static void main

Snap-To lines when aligning controls at Runtime

本秂侑毒 提交于 2019-12-06 04:23:44
I have an app where users can drag controls around on a Form. But they re asking me for Snap-To lines to make the alignment of controls easier. I have no idea about the snep-to lines and how to implement them - I have looked at: http://msdn.microsoft.com/en-us/library/ms752100.aspx Adorner's, but it says it's only for WPF. And I tried it in WinForms but (as expected) didn't work. How can I get snap-to lines (something like the ones in VS) in my app? Thank you Bael Have you seen this article on CodeProject: Form Designer It features snap-to to the grid on the design surface. In your move

BufferedReader.readLine() waits for input from console

笑着哭i 提交于 2019-12-06 00:59:41
问题 I am trying to read lines of text from the console. The number of lines is not known in advance. The BufferedReader.readLine() method reads a line but after the last line it waits for input from the console. What should be done in order to avoid this? Please see the code snippet below: public static String[] getLinesFromConsole() { String strLine = ""; try { // Get the object of DataInputStream InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader

Drawing curved lines to connect elements on web page

帅比萌擦擦* 提交于 2019-12-05 18:29:27
I have been tasked with turning this rough idea into a live page. While I have a basic structure established, I am wondering the best way to go about creating the curved lines that connect the months. Should I just create images and over lay them? Is there a way to draw them with some kind of scripting/coding? Canvas? I don't know the best way to do this. I just put this together to show you that it is very possible and there are probably other ways to do it. #upper-line { border: solid 1px #000; width:80%; height: 250px; border-radius: 50%; left:55px; border-right: none; border-top: none;

Python. Join specific lines on 1 line

折月煮酒 提交于 2019-12-05 17:45:41
Let's say I have this file: 1 17:02,111 Problem report related to router 2 17:05,223 Restarting the systems 3 18:02,444 Must erase hard disk now due to compromised data I want this output: 1 17:02,111 Problem report related to router 2 17:05,223 Restarting the systems 3 18:02,444 Must erase hard disk now due to compromised data Been trying in bash and got to a kind of close solution but I don't know how to carry this out on Python. Thank you in advance If you want to remove the extea lines : For this aim you can check 2 condition for each like one if the line don't followed by an empty new

Drawing lines in code using C# and WPF

删除回忆录丶 提交于 2019-12-05 09:25:02
问题 I'm trying to create a digital clock display using 7 segment displays. I can draw lines in XAML by using code like this: <Line Name="line7" Stroke="Black" StrokeThickness="4" X1="10" X2="40" Y1="70" Y2="70" Margin="101,-11,362,250" /> But when I try to do it in code(from MainWindow()), it doesn't work: Line line = new Line(); Thickness thickness = new Thickness(101,-11,362,250); line.Margin = thickness; line.Visibility = System.Windows.Visibility.Visible; line.StrokeThickness = 4; line.Stroke

How to find N longest lines in a text file and print them to stdout?

有些话、适合烂在心里 提交于 2019-12-05 08:49:46
The first line contains the value of the number 'N' followed by multiple lines. I could solve it in order of n^2 algorithm. Can someone suggest a better one? You can use a minimum-heap and do it in O(n*(log(N))): heap = new Min-Heap(N) foreach line in text: if length(line) > heap.min(): heap.pop() heap.insert(line) foreach line in heap: print to stdout: line. it could also be done in O(n) using Select(N) (which selects the Nth number) followed by partition around the Nth number (which arranges all the with size larger or equal to the Nth number to one side of it). i = Select(lines, N)

Remove lines which are between given patterns from a file (using Unix tools)

随声附和 提交于 2019-12-05 05:17:21
I have a text file (more correctly, a “German style“ CSV file, i.e. semicolon-separated, decimal comma) which has a date and the value of a measurement on each line. There are stretches of faulty values which I want to remove before further work. I'd like to store these cuts in some script so that my corrections are documented and I can replay those corrections if necessary. The lines look like this: 28.01.2005 14:48:38;5,166 28.01.2005 14:50:38;2,916 28.01.2005 14:52:38;0,000 28.01.2005 14:54:38;0,000 (long stretch of values that should be removed; could also be something else beside 0) 01.02