w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Change encoding of text file (shell archive or script for antique kernel text to ASCII text, with CRLF, LF line terminators)
Unix uses a single character for line termination. If you want to convert your file with CRLF to single character termination, you can do the following: sed -e 's/<CTRL-V><CTRL_M>//' filename where <CTRL-V> is the Control key pressed with V (do not include < and > characters in the command.

Categories : Bash

how to read from text file to textbox in visual basic 1 line every hit on button
Assuming you are reading from a file and displaying lines on the form, you can use these. If you have a large file (> 10MB), then you can use this pattern... (syntax from memory, please excuse mistype) Public Class YourFormNameHere Private _CurrentLine as Integer = 0 Private Sub btnClicked(sender, e) 'or enter pressed - This is YOUR keypress event handler. Using Dim sr as New StreamReader(filePath) Dim _curIndex as Integer = 0 While (sr.EndOfFile == false) Dim _line as String = sr.ReadLine() If (_curIndex = _CurrentLine) txtLineDisplay.Text = _line Break End If curIndex += 1 End While End Using End Sub End Class If you have a smaller file, then use this pattern. Public Class YourFormNameHere Private _Lines as St

Categories : Vb.Net

Button to open text file won't function with text file not in class root directory
This is windows specific code, I think the problem is using the file separator "/" instad of "", try changing your code to Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "config\gameItems.txt");

Categories : Java

Grab input from text file and use in CLI vbs/batch
If the WWN lines don't contain additional text you could extract them like this: Set fso = CreateObject("Scripting.FileSystemObject") Set sh = CreateObject("WScript.Shell") Set re = New RegExp re.Pattern = "^[0-9a-e]{2}(:[0-9a-e]{2}){7}$" re.IgnoreCase = True Set f = fso.OpenTextFile("C:yourinput.txt") Do Until f.AtEndOfStream line = f.ReadLine If re.Test(line) Then sh.Run "hbacmd SetDriverParam " & line & " G P QueueDepth 32", 0, True End If Loop f.Close

Categories : Batch File

Python 3.3: How to grab every 5th word in a text file?
Using your method of defining words withstr.split(), either of the following will do what you want: textInput = """ I'm trying to have my program grab every fifth word from a text file and place it in a single string. For instance, if I typed "Everyone likes to eat pie because it tastes so good plus it comes in many varieties such as blueberry strawberry and lime" then the program should print out "Everyone because plus varieties and." I must start with the very first word and grab every fifth word after. I'm confused on how to do this. Below is my code, everything runs fine except the last 5 lines.""" everyfive = ' '.join(word for i,word in enumerate(textInput.split()) if not i%5) # or more succinctly everyfive = ' '.join(textInput.split()[::5]) print(repr(everyfive)) Either way, th

Categories : Python

Delete/edit/add a line of text from a text file
I would recommend a Streamreader and ReadLine() for reading all lines and a List for saving them. So the code for the reading + saving would be: Dim lineList As New List(Of String)() Dim sr As StreamReader = New StreamReader(path) Do While sr.Peek() >= 0 lineList.add(sr.ReadLine()) Loop Then add some labels (with the text) to your form: For i as Integer = 0 to lineList.Count - 1 Dim Label as New Label lineLabel.Text = lineList.Item(i) lineLabel.Location = New Point(0, 50 * i) 'you can change the 50 to whatever value you want Me.Controls.Add(Label) AddHandler Label.Click, AddressOf Me.Label_Click 'here we add a handler for the label-clicks Next The handler will look like this then: Private Sub Label_Click(ByVal sender As System.Object, ByVa

Categories : Vb.Net

How do I replace a certain line on a text file with diferent text?
You seem to be confusing static and non-static methods: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { System::String^ txtfile = L"C:\Users\acer\Desktop\aaa.txt"; array<System::String^>^ lineArray = System::IO::File::ReadAllLines(txtfile); System::Collections::Generic::List<System::String^>^ lineList; lineList = gcnew System::Collections::Generic::List<System::String^>(lineArray); lineList->RemoveAt(6); System::IO::File::WriteAllLines(txtfile, fileList->ToArray()); }

Categories : C++

How to update the first line of text in a text file in VB.NET
In C#.Net: var filepath = "/file/path"; var list = File.ReadAllLines(filepath).ToList(); list.Insert(0, String.Format("Records in this file: {0}", list.Count)); File.WriteAllLines(filepath, list); In VB.Net (I think, i dont really use VB) Dim filepath = "/file/path" Dim list = File.ReadAllLines(filepath).ToList() list.Insert(0, [String].Format("Records in this file: {0}", list.Count)) File.WriteAllLines(filepath, list)

Categories : Dotnet

Adding "new line"s to text in text supporting objects (i.e Buttons, Rich Text boxs) both in and out of code
" " is the escaped character for a line break. So code like: label.Text = "This is a button"; Should put the word button on a new line. Edit: If you want to do it using the properties window in designer, click on the arrow on the far right of the text property field and it will open a small box. If you type multiple lines on that as you would normally (ie actually pressing enter, not using ) then the component will treat them as new lines and put the new lines in for you.

Categories : C#

Perl Program to Read a Text File, Search for text within the File and copy the text to a new file
Why not awk? awk '/ Directory of /{at=$3;print;next}{print $0""FS""at}' your_file Perl: perl -lne 'if(/ Directory of (.*)/){$a=$1;print}else{$_.=" ".$a;print}' your_file if you want to do an inline replacement: perl -i -lne 'if(/ Directory of (.*)/){$a=$1;print}else{$_.=" ".$a;print}' your_file

Categories : Regex

Read from text file, capture text, write to another text file in specific syntax
I'd personally do something like that with Perl, because I'm familiar with Perl and it works great for these kinds of tasks. You can also write a sed one-liner to get that done. If you're not a fan of Perl, any modern dynamic language should let you get the job done with minimal effort. EDIT: An example Perl script (full file for readability) would look like this: use warnings; use strict; while (my $line = <>) { $line =~ /^s*(.+?), '(.+?)', '(.+?)';$/; # Doesn't handle internal escaping print "DELETE ATTRIBUTE "$1" IN FOLDER "$2" FROM PROJECT "$3"; "; } See the result.

Categories : Misc

Objective C - Create text file to read and write line by line in Cocoa
Well, to create a file, just use [[NSFileManager defaultManager] createFileAtPath:@"Your/Path" contents:nil attributes:nil]; This creates an empty file, which you can write to or read from. To write text (or XML), just use NSString's writeToFile:atomically:encoding:error: method like this NSString *str = //Your text or XML [str writeToFile:"Your/Path" atomically:YES encoding:NSUTF8StringEncoding error:nil]; To read from a file, just make an NSString with the contents of that file NSString *contents = [NSString stringWithContentsOfFile:@"Your/Path"]; or, if it does not contain a string, get an NSData object from the file NSData *contents = [NSData dataWithContentsOfFile:@"Your/Path"];

Categories : Objective C

Extract a numeric substring and another line as variables from multi-line text file
You could use the following regex for the second line: ^.*(d{6})[^d].*$ Here, the first named sub-group would denote the digits of interest. For example, using Notepad++, Orginal text: Replace options: Resulting text: The regex should remain more or less the same across environments. You might need to simply change the way the named subexpression ($1 here) is referenced.

Categories : Regex

How to read data from Excel and write it to text file line by line?
You should open the output.txt file with append mode: file = open("Output.txt", "a") Also, you should do this before entering the loop, and it should be closed after that loop. Update: In cases like this one, you could use with instead of closing the file handle at the end. Also including the good suggestion made by @Josh in his own answer, the code could be this: import xlrd import os.path wb = xlrd.open_workbook(os.path.join('D:TRB 2014 Data','SPS1 demo data.xlsx')) wb.sheet_names() sh = wb.sheet_by_index(0) i = 1 with open("Output.txt", "a") as my_file: while sh.cell(i,11).value != 0: Load = sh.cell(i,11).value all_d = sh.col_values(i, 13, 19) DB1 = Load + " " + (" ".join(all_d)) my_file.write(DB1 + ' ') i += 1

Categories : Python

Assigning variables to values in a text file with 3 columns, line by line
while read x y z; do echo x=$x y=$y z=$z done < input.txt The above requires that none of your columns contain any whitespace. EDIT: In response to comments, here is one technique to handle numbering the lines: nl -ba < input.txt | while read line x y z rest; do ~/data/standard/MNI152_T1_2mm -mul 0 -add 1 -roi $x 1 $y 1 $z 1 0 1 point -odt float > NewFile$line done

Categories : Bash

sending text file from server to client line by line in winsocks
You need to also send a newline. getline reads all characters until a newline, but doesn't store the newline in the string. So when you send the string, it doesn't have a newline. You can either send a " " on its own, but probably better to add a newline to the existing string. E.g. : stringToUpper(STRING); STRING += " "; ...

Categories : C++

How to have a radio button and a text field on the same line?
Consider applying some CSS to the elements. input[type=radio], input[type=text] { display: inline-block; vertical-align: middle; } input[type=radio] { width: 10%; } input[type=text] { width: 89%; }

Categories : Javascript

Multiple line text beside a button without using float
You will have to add some widths and try using inline-block instead of inline. jsFiddle Note: inline-block is not supported in IE7 and earlier so be careful. For older IE versions you can use *display:inline;zoom:1;

Categories : HTML

reading a tab delimited text file line by line get data after in vb.net
RichTextBox_WD.Text = String.Join(vbCrLf, File.ReadLines(vcFile).Select(Function(line) Dim format = "RECEIVED ON: {0} FROM: {1} AMOUNT {2}" Dim fields = line.Split(vbTab) Return String.Format(format, fields(0), fields(1), fields(2)) End Function) I prefer to create a Joined extension method on IEnumerable<T> which wraps String.Join (taking a delimiter and an optional transformation delegate), and a Formatted extension method on String which wraps String.Format: RichTextBox_WD.Text = Fil

Categories : Vb.Net

Compare a text file line by line with a dynamic variable
If I understand the question correctly, this is what you need: File insert = new File("sample.txt"); BufferedReader br = new BufferedReader(new FileReader(insert)); String strLine; Boolean hasLine = false; while ((strLine = br.readLine()) != null) { if(strLine.equals(field)) { hasLine = true; break; } } br.close(); if (!hasLine) { FileWriter fw = new FileWriter(insert, true); BufferedWriter bw = new BufferedWriter(fw); bw.append(field + " "); // assumes field does not already have a newline bw.flush(); bw.close(); } Notice the break;. This will discontinue the while loop, since you already have the answer to what you are looking for. Your original code was doing: for every line: Do I equal field? Yes: goto next line No: append f

Categories : Java

How to delete a line from a text file using the line number in python
You start counting at one, but python indices are always zero-based. Start your line count at zero: for num, line in enumerate(myFile): # default is to start at 0 or subtract one from num, deleting from lines (not line): del lines[num - 1] Note that in order for your .readlines() call to return any lines, you need to either re-open the file first, or seek to the start: myFile.seek(0)

Categories : Python

Iterating though a text file in Java so that each line has information about that line
I cleaned up your code a little bit. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Palindrome { int charCount = 0; int totalWordCount = 0; public static String isPalindrome(String str) { if(str.equals(new StringBuffer().append(str).reverse().toString())) { return "a"; } else { return "not a"; } } public static int getNumberOfWords(String str) { return str.isEmpty() ? 0 : str.split("\s+").length; } public void process(File file) { try { Scanner sc = new Scanner(file); int i = 0; while(sc.hasNextLine()) { i++; String line = sc.nextLine(); int wordCount =

Categories : Java

Node.js: Inserting a line after a particular line in a text file?
Callback in for loop is not a good idea. Try this code - fs.readFile('nginx.conf', function(err, data) { if(err) throw err; //data = data.toString(); var array = data.toString().split(" "); array[4] ='deny '+cli.getValue(options.ip)+':'+cli.getValue(options.port); for(i=0;i<array.length;i++) { fs.appendFileSync('nginx1.conf', array[i]+' '); } });

Categories : Javascript

write text file line by line python
If you have the Names and Locations as a list, you can do this: data = [('James','Germany'), ('Gail','US'), ('Merkel','Poland')] with open('output', 'w') as f: for name,place in data: f.write("Name=%s Location=%s " % (name, place))

Categories : Python

write a text file in Python, line by line
You have print new_str for every line in test.txt. But you only write one line to the file after the loop. Changing the code to write after each print: outf = open('result.txt', 'w') for line in fileinput.input("test.txt"): new_str = re.sub('[^a-zA-Z0-9 .]'," ", line) print new_str outf.write(new_str + ' ') outf.close() will do what you want.

Categories : Python

textillate text animation repeat text line after line
You can animate a list of texts with the following markup: <h1 class="tlt"> <ul class="texts"> <li>Some Title</li> <li>Another Title</li> </ul> </h1> Is this the effect you are trying to achieve? http://jsfiddle.net/jschr/9dKum/

Categories : Jquery

read a text file line by line
It's all built into StreamReader: using (var sr = new StreamReader(myFile)) { string line; while ((line = sr.ReadLine()) != null) { // line is the text line } }

Categories : File

How to append text in every line of a file except for the first line
How about: sed -e '2,$ s/$/|Paris/' < abc.txt And including the header: sed -e '1 s/$/|Place/' -e '2,$ s/$/|Paris/' < abc.txt For the last line, you must have an extra blank line in the file. So, delete all lines containing nothing but zero or more spaces: sed -e '/^ *$/ d' -e '1 s/$/|Place/' -e '2,$ s/$/|Paris/' < abc.txt

Categories : File

parsing a text file with first line all 1's and second line all 2's
You can create a vector of vectors as vector<vector<string>> VEC; And keep on adding words to VEC[0] for the first line and then increment the counter as you encounter a newline character to point to VEC[1] and so on.

Categories : C++

Grab url from href and text
First look at parsing-html-in-python-lxml-or-beautifulsoup. I read it and never looked at the soup. I guess because I find lxml so easy. I am sure there are different ways to do what you asked, perhaps there are easier ones. But I'll show what I use. In lxml you can use XPath it's like using regex for XML/HTML. This code below will find all "a" tags that have "http" attribute and print all links that start with http. This should help you get started on your parsing. from lxml.html import etree tree = etree.parse("my.html", etree.HTMLParser()) root = tree.getroot() links = root.findall('*//a[@href]') foreach link in links: if link.get("http").startswith("http"): print link.get("http")

Categories : Python

Inserting text from text file into MySQL TEXT column
This is a possible duplicate of this question: http://serverfault.com/questions/316691/mysql-binlog-format-dilemma Anyway, the key is Statement is unsafe because it uses a system function that may return a different value on the slave. When the MySQL database is setup to use replication, system functions like load_file can cause issues. The file C: emp exttoinset.txt is likely different between the master server and the slave server (or may not even exist on one of them). When using replication, it is best to avoid system functions (like load_file and NOW()) because the values will be different when executed on different servers. If you want to load a file into a MySQL database that uses replication, consider using PHP's file_get_contents to read the file, and then use that to insert

Categories : PHP

text file doesn't match when i try to create text box according to the text file
It's creating 10 more because you have 10 lines that ends with a comma. Say you have a string like: var s = "A,B,C," Splitting this would result in 4 string, the last one being empty. Now reproduce this for 10 lines and you will get the same behaviour as you are having. If that's unwanted behaviour, you need to change your logic to take into account a line that is ending with a comma.

Categories : C#

How do I strip a line of text or amount of words/characters from stored text with CSS/Javascript?
In JavaScript on a String Object there is a "substring(from, to)" Method, by which you can split Strings at a certain position: http://www.w3schools.com/jsref/jsref_substring.asp So you could use the substring(0,1) Method to split your String at the first letter. Afterwards you could colour the string with the first letter blue. I don't know if that is the simpliest possible Solution, but that's how i would do it. Hope this helps.

Categories : Javascript

I need to show an PDF in which text of pdf will auto fit to the screen width and remaining text move to the next line
** Try This** WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); Use for Zooming Purpose settings.setLoadWithOverviewMode(true); Use for Zooming Purpose settings.setUseWideViewPort(true); Use for Zooming Purpose mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

Categories : Android

How to extract two folder path C: (same Type File: e.g Text Document) and name of the file into text file with the file size in kb
The error you observe is caused by the signature of your procedure ListFiles. In VBScript all variables/parameters are of type Variant, so you must not explicitly specify a type. Change this: Sub ListFiles(f, folderPath As String, fileType As String) into this: Sub ListFiles(f, folderPath, fileType)

Categories : Vbscript

In phone landscape, show more text per line, not just bigger text
So, if you want to specify the font-size for landscape orientation, I think you can use one of the following things and manipulate with them: <link rel="stylesheet" media="screen and (orientation: landscape)" href="landscape-screen.css" /> or <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1" /> or @media all and (orientation:landscape) { … } or something like that. For details: W3C Media Queries

Categories : CSS

Text Grab from a large content
If you have only one of these quoted words in the string the easiest thing to do will be: $myArr = explode('"',$string); // break the string to array with " as dilimeter echo $myArr[1]; // echo the second element. Update: for many quots - pick only the one after string=: $myPos = strpos($string,'string="')+8; // get the position of string after 'string="' $result = substr($string,$myPos,strpos($string,'"',$myPos)-$myPos); echo $result; Note: this should be a lot more efficient than using regex - phpFiddle result: Yotam: 0.014078ms, bkilinc: 0.048885ms

Categories : PHP

How to grab text from URL and place in JS array?
Make an AJAX request and you will have access to the returned content. Using jQuery: function getWords(){ var url = "http://www.somethingrandom.com/poop" $.get(url, function(data) { var list = $('pre:eq(0)', data).html; var listLength = list.length; alert( listLength); }, 'html'); }

Categories : Javascript

Regexp grab all text following last match
This is the regex you will need: /^.*?(d+(?=D*$)s*)/ And just replace matched text with empty string "" PHP code: $s = preg_replace('/^.*?(d+(?=D*$)s*)/', '', 'Foo Oz'); //=> Foo Oz $s = preg_replace('/^.*?(d+(?=D*$)s*)/', '', '1/2 Oz'); //=> Oz Live Demo: http://ideone.com/u887D7

Categories : PHP

Grab inner text from HTML that isn't from a header
Just remove unwanted tags, then get body.innerText: string[] tagsToRemove = { "h1", "h2", "h3", h4", "h5", "h6" }; List<string> tagsToRemoveList = tagsToRemove.ToList(); doc.DocumentNode.Descendants() .Where(n => tagsToRemoveList.Contains(n..Name.ToLowerCase())) .ToList() .ForEach(n => n.Remove());

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.