text-files

Read specific line in text file

眉间皱痕 提交于 2019-12-10 12:02:24
问题 Ok so I've got a program that needs to read from a text file that looks like this [Characters] John Alex Ben [Nationality] Australian American South African [Hair Colour] Brown Black Red What I would like to do is only have one method that reads a section depending on the parameter that is passed. Is this possible and how? 回答1: var sectionName = "[Nationality]"; string[] items = File.ReadLines(fileName) //read file lazily .SkipWhile(line => line != sectionName) //search for header .Skip(1) /

Opening a large text file (30mb) consumes 500,000k of Firefox memory

泪湿孤枕 提交于 2019-12-10 11:59:02
问题 I was initially dabbling with IFrames to launch a document, and found that for large files, the memory in all browsers (I first noticed this in FF) jumped to 500,000 K. At first I thought it might have been some bad JS code that I had written, but removing all the extraneous code and just OPENING the text file still displayed the same problem. So right now, all I'm doing is going to a site http://url/largefile, and seeing the file slowly display to the screen. Is there any efficient way for

Regex: Match the text before the end of line

心已入冬 提交于 2019-12-10 11:47:58
问题 I have a file that looks like this: J6 INT-00113G 227.905 5.994 180 ~!@#$%&^) J3 INT-00113G 227.905 -203.244 180 12341341312315 U13 EXCLUDES -42.210 181.294 180 QFP128 U3 IC-00276G 5.135 198.644 90 B%GA!@-48 U12 IC-00270G -123.610 -201.594 0 SOP8_000 J1 INT-00112G 269.665 179.894 180 SOIC16_1 J2 INT-00112G 269.665 198.144 180 SOIC16-_2 .. .......... ....... ....... ... ................ And I would like to match the end value in the 6th column in order to remove it from a list. The length of

navigating text file searches in python

无人久伴 提交于 2019-12-10 11:43:25
问题 here is sample of the text file I am working with: <Opera> Tristan/NNP and/CC Isolde/NNP and/CC the/DT fatalistic/NN horns/VBZ The/DT passionate/JJ violins/NN And/CC ominous/JJ clarinet/NN ;/: The capital letters after the forward slashes are weird tags. I want to be able to search the file for something like "NNP,CC,NNP" and have the program return for this segment "Tristan and Isolde" , the three words in a row that match those three tags in a row. The problem I am having is I want the

Dragging files into rich textbox to read text in file

a 夏天 提交于 2019-12-10 11:38:37
问题 I'm having a problem with dragging and dropping files onto a richTextBox, every time I drag a text file onto it, it turns into a picture of the text file with its name under it. Double click the file and it opens up using the system default application (ie notepad for text files, etc). basically its making shortcuts in the richTextBox, when i want it to read the text in the file. Based on this code, the text from the file should extract into richTextBox1 class DragDropRichTextBox :

What is the most elegant way to write a text/binary file with c++?

旧城冷巷雨未停 提交于 2019-12-10 10:27:27
问题 I found some good results on reading e.g.: Read txt with iterators and preallocation, or read into containers. So I wondered how would I write most elegant a std::string into a file? Edit: When reading I can preallocate space for the string via seek and tellg, since I know the size of the string, how could I tell the filesystem how much I want to write? 回答1: Here's a tiny example on how to output a std::string , but you should really read up on fstream #include <iostream> #include <fstream>

Reading a space delimited text file where first column also has spaces

☆樱花仙子☆ 提交于 2019-12-10 10:15:05
问题 I'm trying to read a text file into R that looks like this: Ant farm 45 67 89 Cookie 5 43 21 Mouse hole 5 87 32 Ferret 3 56 87 Etc. My problem is that the file is space delimited and the first variable has some entries that include a space so reading into R creates an error due to different rows having more columns. Does anyone know a way to read this in? 回答1: Ben's approach works great, but here is another approach using `strapplyc , gsubfn or strapply from the gsubfn package. First read in

progress bar for reading lines in text file

偶尔善良 提交于 2019-12-10 10:07:50
问题 I'm reading lines form in a text file and then performing actions per line. Due to the size of the text file and the time of each action 500 => seconds. I would like to be able to view the progress but not sure where to start. Here is an example script I'm using, how would write that for this? import os tmp = "test.txt" f = open(tmp,'r') for i in f: ip = i.strip() os.system("ping " + ip + " -n 500") f.close() test.txt: 10.1.1.1 10.1.1.2 10.2.1.1 10.2.1.1 回答1: Here's a handy module: progress

How do I match a word in a text file using python?

感情迁移 提交于 2019-12-10 07:01:14
问题 I want to search and match a particular word in a text file. with open('wordlist.txt', 'r') as searchfile: for line in searchfile: if word in line: print line This code returns even the words that contain substrings of the target word. For example if the word is "there" then the search returns "there", "therefore", "thereby", etc. I want the code to return only the lines which contain "there". Period. 回答1: split the line into tokens: if word in line.split(): 回答2: import re file = open(

TXT File or Database?

a 夏天 提交于 2019-12-10 03:12:30
问题 What should I use in this case (Apache + PHP) ? Database or just a TXT file ? My priority #1 is speed . Operations Adding new items Reading items Max. 1 000 records Thank you. Database (MySQL) +----------+-----+ | Name | Age | +----------+-----+ | Joshua | 32 | | Thomas | 21 | | James | 34 | | Daniel | 12 | +----------+-----+ TXT file Joshua 32 Thomas 21 James 34 Daniel 12 回答1: Have you explored other DHTs? Project Voldemort Memcached + MySQL Update 1 If you don't have memcached and Voldemort