lines

Android Development: Count EditText Lines on textChanged?

前提是你 提交于 2019-12-04 14:15:20
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! Whiler 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().toString()); LineNumberReader lnr = new LineNumberReader(sr); try { while (lnr.readLine() != null){}

Remove Duplicate Lines from Text using Java

旧街凉风 提交于 2019-12-04 11:08:58
I was wondering if anyone has logic in java that removes duplicate lines while maintaining the lines order. I would prefer no regex solution. Emil 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(String args[]) { try { // Open the file that is the first // command line parameter FileInputStream fstream

Find most frequent line in file in bash

核能气质少年 提交于 2019-12-04 07:39:30
Suppose I have a file similar to as follows: Abigail 85 Kaylee 25 Kaylee 25 kaylee Brooklyn Kaylee 25 kaylee 25 I would like to find the most repeated line, the output must be just the line. I've tried sort list | uniq -c but I need clean output, just the most repeated line (in this example Kaylee 25 ). Kaizen ~ $ sort zlist | uniq -c | sort -r | head -1| xargs | cut -d" " -f2- Kaylee 25 does this help ? Sina Bahram IMHO, none of these answers will sort the results correctly. The reason is that sort, without the -n , option will sort like this " 1 10 11 2 3 4 ", etc., instead of " 1 2 3 4 10

How do I Join the line above after current line?

若如初见. 提交于 2019-12-04 05:32:31
I know these commands in Vim: J : Join line below after current line -J : Join current line after line above but how do I join the line above after current line? There are many ways to do it. One would be… deleting the line above and appending it to the end of the line below: k move up one line ^ move to the first printable character y$ yank to the end of the line "_d get rid of the now useless line by deleting it into the black hole register $ move to the end of the line p put the deleted text You can also use the ex-command :m-2|j m-2 has the effect of moving the current line to 2 lines

Drawing lines in code using C# and WPF

和自甴很熟 提交于 2019-12-03 22:16:41
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 = System.Windows.Media.Brushes.Black; line.X1 = 10; line.X2 = 40; line.Y1 = 70; line.Y2 = 70; The idea

Why do I have lines going across my libgdx game using Tiled?

允我心安 提交于 2019-12-03 17:38:41
问题 I'm using LibGdx and Tiled and when moving around the screen, there are both horizontal and vertical lines appearing on the game. I can post any code you need, if necessary. How do I get these lines to stop? Here's a gfycat gif of the lines: http://gfycat.com/FastUnnaturalAmericanwirehair Edit: Here's a small bitbucket repository, as small as I could get it that has the same glitch in it: https://bitbucket.org/Chemical_Studios/example-of-line-glitch/src

How can I delete the last N lines of a file?

偶尔善良 提交于 2019-12-03 17:16:44
Can someone give some hints of how to delete the last n lines from a file in Perl? I have a very large file of around 400 MB, and I want to delete some 125,000 last lines from it. You can use Tie::File to handle the file as an array. use Tie::File; tie (@File, 'Tie::File', $Filename); splice (@File, -125000, 125000); untie @File; An alternative is to use head and wc -l in the shell. edit: grepsedawk reminds us of the -n option to head , no wc necessary: head -n -125000 FILE > NEWFILE Schwern As folks have suggested Tie::Array already, which does the job well, I'll lay out the basic algorithm

Objective C label line spacing?

孤者浪人 提交于 2019-12-03 16:22:50
Is there a way to set the distance of two lines within a UILabel ? I tried to do it within Interface Builder but without success. The code you want will be something like this: NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString:@"Sample text"]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setLineSpacing:24]; [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, strLength)]; uiLabel.attributedText = attrString; You can use NSAttributedString to add spacing between two lines within a

Returning lines that differ between two files (Python)

别等时光非礼了梦想. 提交于 2019-12-03 15:09:56
问题 I have two files with tens of thousands of lines each, output1.txt and output2.txt. I want to iterate through both files and return the line (and content) of the lines that differ between the two. They're mostly the same which is why I can't find the differences (filecmp.cmp returns false). 回答1: You can do something like this: import difflib, sys tl=100000 # large number of lines # create two test files (Unix directories...) with open('/tmp/f1.txt','w') as f: for x in range(tl): f.write('line

Why do I have lines going across my libgdx game using Tiled?

删除回忆录丶 提交于 2019-12-03 07:33:31
I'm using LibGdx and Tiled and when moving around the screen, there are both horizontal and vertical lines appearing on the game. I can post any code you need, if necessary. How do I get these lines to stop? Here's a gfycat gif of the lines: http://gfycat.com/FastUnnaturalAmericanwirehair Edit: Here's a small bitbucket repository, as small as I could get it that has the same glitch in it: https://bitbucket.org/Chemical_Studios/example-of-line-glitch/src/8eeb153ec02236d836763072611bd7aa55d38495/minimalExample/src/com/weebly/chemicalstudios/minEx/?at=master noone This is because you need to add