text-files

C++ string parsing (python style)

白昼怎懂夜的黑 提交于 2019-11-28 05:27:01
I love how in python I can do something like: points = [] for line in open("data.txt"): a,b,c = map(float, line.split(',')) points += [(a,b,c)] Basically it's reading a list of lines where each one represents a point in 3D space, the point is represented as three numbers separated by commas How can this be done in C++ without too much headache? Performance is not very important, this parsing only happens one time, so simplicity is more important. P.S. I know it sounds like a newbie question, but believe me I've written a lexer in D (pretty much like C++) which involves reading some text char

Reading data from text file and delimiting

梦想与她 提交于 2019-11-28 04:19:53
问题 I have an Excel 2010 spreadsheet, and I am reading in information from a .txt file (and another .xls file in future). This text file has 3 elements per row; firtname, surname and Job title, and each element is separated by a comma. I have the data reading and pasting into Excel, however each row is pasted into the one cell. I am looking to paste each element into different columns. I know that I should try and delimit, but I just can't figure out the syntax. My question is how do I separate

C# - Read .txt file into TextBox

有些话、适合烂在心里 提交于 2019-11-28 04:16:34
问题 I am trying to read a .txt file into a multi-line text box with the following code. I have gotten the file dialog button to work perfectly, but I am not sure how to get the actual text from the fiile into the textbox. Here is my code. Can you help? private void button_LoadSource_Click(object sender, EventArgs e) { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files

MATLAB: How do you insert a line of text at the beginning of a file?

﹥>﹥吖頭↗ 提交于 2019-11-28 03:54:51
问题 I have a file full of ascii data. How would I append a string to the first line of the file? I cannot find that sort of functionality using fopen (it seems to only append at the end and nothing else.) 回答1: Option 1: I would suggest calling some system commands from within MATLAB. One possibility on Windows is to write your new line of text to its own file and then use the DOS for command to concatenate the two files. Here's what the call would look like in MATLAB: !for %f in ("file1.txt",

Best Free Text Editor Supporting *More Than* 4GB Files? [closed]

淺唱寂寞╮ 提交于 2019-11-28 02:39:58
I am looking for a text editor that will be able to load a 4+ Gigabyte file into it. Textpad doesn't work. I own a copy of it and have been to its support site, it just doesn't do it. Maybe I need new hardware, but that's a different question. The editor needs to be free OR, if its going to cost me, then no more than $30. For Windows. VonC glogg could also be considered, for a different usage: Caveat (reported by Simon Tewsi in the comments , Feb. 2013) One caveat - has two search functions, Main Search and Quick Find . The lower one, which I assume is Quick Find , is at least an order of

Editing a text file in place through C#

折月煮酒 提交于 2019-11-28 01:49:42
I have a huge text file, size > 4GB and I want to replace some text in it programmatically. I know the line number at which I have to replace the text but the problem is that I do not want to copy all the text (along with my replaced line) to a second file. I have to do this within the source file. Is there a way to do this in C#? The text which has to be replaced is exactly the same size as the source text (if this helps). Since the file is so large you may want to take a look at the .NET 4.0 support for memory mapped files . Basically you'll need to move the file/stream pointer to the

How to save data in .txt file in MATLAB

点点圈 提交于 2019-11-28 01:14:26
I have 3 txt files s1.txt, s2.txt, s3.txt .Each have the same format and number of data.I want to combine only the second column of each of the 3 files into one file. Before I combine the data, I sorted it according to the 1st column: UnSorted file: s1.txt s2.txt s3.txt 1 23 2 33 3 22 4 32 4 32 2 11 5 22 1 10 5 28 2 55 8 11 7 11 Sorted file: s1.txt s2.txt s3.txt 1 23 1 10 2 11 2 55 2 33 3 22 4 32 4 32 5 28 5 22 8 11 7 11 Here is the code I have so far: BaseFile ='s' n=3 fid=fopen('RT.txt','w'); for i=1:n %Open each file consecutively d(i)=fopen([BaseFile num2str(i)'.txt']); %read data from

How to save a structure array to a text file

荒凉一梦 提交于 2019-11-28 01:13:16
问题 In MATLAB how do I save a structure array to a text file so that it displays everything the structure array shows in the command window? 回答1: I know this thread is old but I hope it's still going to help someone: I think this is an shorter solution (with the constraint that each struct field can contain scalar,arrays or strings): %assume that your struct array is named data temp_table = struct2table(data); writetable(temp_table,'data.csv') Now your struct array is stored in the data.csv file.

Putting a .txt file into a DataGridView

杀马特。学长 韩版系。学妹 提交于 2019-11-28 01:12:32
I have an openFileButton that, when clicked, will open a file that looks like this: RefDeg Part# Xcntr Ycntr Rot PkgStyle U6 IC-00279G 33.411 191.494 0 QFP32 U1 IC-00272G 38.011 200.644 90 BGA177 U5 IC-00273G 46.311 179.494 0 QFP40 R54 EXCLUDES 36.411 173.694 0 0402_2 R71 EXCLUDES 38.236 186.994 0 0402_2 R39 EXCLUDES 38.861 188.544 90 0402_2 C23 CAP-00130G 37.911 178.854 90 0402_3 C88 CAP-00010G 52.036 179.019 0 0603_4 C89 CAP-00010G 43.561 173.744 90 0603_3 X1 XTL-00013G 49.211 204.819 0 Crystal X2 XTL-00012G 53.061 183.469 0 Crystal D1 LED-00011G 58.611 181.394 0 LED U10 IC-00198G 56.661 205

Quickest way to read text-file line by line in Java

旧城冷巷雨未停 提交于 2019-11-28 00:20:15
问题 For log processing my application needs to read text files line by line. First I used the function readLine() of BufferedReader but I read on the internet that BufferedReader is slow when reading files. Afterwards I tried to use FileInputStream together with a FileChannel and MappedByteBuffer but in this case there's no function similar to readLine() so I search my text for a line-break and process it: try { FileInputStream f = new FileInputStream(file); FileChannel ch = f.getChannel( );