text-files

Batch - edit specified line in text file

大兔子大兔子 提交于 2019-11-28 10:33:54
问题 For example, line number 2 reads: "0" (without quotes). I want to change that 0 to a 1, without changing anything else in the text file. I know what line the values will be on, so all i need to know is how to change that value to another value that I specify. I also will have to to the same with strings, not just numbers. Example: From: 4.7 0 check 0 1 0 0 To: 4.7 1 check 0 1 0 0 Thanks! 回答1: try this: @ECHO OFF &SETLOCAL SET "file=file" SET /a Line#ToSearch=2 SET "Replacement=0" (FOR /f

How do I read and edit a .txt file in C#?

故事扮演 提交于 2019-11-28 10:06:00
For example, I have a txt file that reads: 12 345 45 2342 234 45 2 2 45345 234 546 34 3 45 65 765 12 23 434 34 56 76 5 I want to insert a comma between all the numbers, add a left brace to the begining of each line and a right brace to the end of each line. So after the editing it should read: {12, 345, 45} {2342, 234, 45, 2, 2, 45345} {234, 546, 34, 3, 45, 65, 765} {12, 23, 434, 34, 56, 76, 5} How do I do it? Added some LINQ for fun and profit (room for optimization ;) ): System.IO.File.WriteAllLines( "outfilename.txt", System.IO.File.ReadAllLines("infilename.txt").Select(line => "{" + string

c++: ifstream open problem with passing a string for text file name [duplicate]

拟墨画扇 提交于 2019-11-28 09:54:54
This question already has an answer here: No matching function - ifstream open() 1 answer i'm trying to pass a string from main to another function. this string is a name of text file that needs to be oepened. as far as i can see, i am passing the string alright, but when i try to use ifstream.open(textFileName) , it doesn't quite work. but when i manually hardcode it as ifstream.open("foo.txt") , it works just fine. i would need to use this function several times so i would like to be able to pass in a string of text file name.. here's my main #ifndef DATA_H #define DATA_H #include "Data.h"

Read text file in Java

会有一股神秘感。 提交于 2019-11-28 09:12:32
问题 I have a text file. I would like to retrieve the content from one line to another line. For example, the file may be 200K lines. I want to read the content from line 78 to line 2735. Since the file may be very large, I do not want to read the whole content into the memory. 回答1: Here's a start of a possible solution: public static List<String> linesFromTo(int from, int to, String fileName) throws FileNotFoundException, IllegalArgumentException { return linesFromTo(from, to, fileName, "UTF-8");

StreamWriter limit in C# in text file

十年热恋 提交于 2019-11-28 07:54:16
问题 I have an array list which contains 100 lines. When i try to export it into a text file (txt), the output is only 84 lines and it stops in the middle of the 84th line. When I looked at the file size it showed exactly sharp 4.00KB as if there is some kind of a limit to the stream writer. I tried using different parameters etc. but it kept happening. Here is the code: FileStream fs = new FileStream(path, FileMode.Create); StreamWriter sw = new StreamWriter(fs); ArrayList chartList = GetChart

Why doesn't fwrite() write a Binary File using “wb”, in C, on Mac OS X?

南笙酒味 提交于 2019-11-28 07:44:49
问题 For the sake of learning C and understanding the difference between Binary Files and Text Files, I'm attempting to write a string to file as both file types like so: char * string = "I am a string!"; FILE * filePtrA = fopen("/output.txt", "wt"); fwrite(string, strlen(string), 1, filePtrA); FILE * filePtrB = fopen("/output.bin", "wb"); fwrite(string, strlen(string), 1, filePtrB); fclose(filePtrA); fclose(filePtrB); However both "wt" and "wb" are writing as a Text File, where "wb" should be

Fetching zipped text file and unzipping in client browsers, feasible in Javascript?

有些话、适合烂在心里 提交于 2019-11-28 07:40:23
I am developing a web page containing Javascript. This js uses static string data (about 1-2 MB) which is stored in a flat file. I could compress it with gzip or any other algorithm to reduce the transfer load. Would it be possible to fetch this binary file with Ajax and decompress it into a string (which I could split later) in the client browser. If yes, how can I achieve this? Does anyone have a code example? And another library or site is this one, although it has few examples it has some thorough test cases that can be seen. https://github.com/imaya/zlib.js Here are some of the complex

How do I split a huge text file in python

喜欢而已 提交于 2019-11-28 07:26:22
I have a huge text file (~1GB) and sadly the text editor I use won't read such a large file. However, if I can just split it into two or three parts I'll be fine, so, as an exercise I wanted to write a program in python to do it. What I think I want the program to do is to find the size of a file, divide that number into parts, and for each part, read up to that point in chunks, writing to a filename .nnn output file, then read up-to the next line-break and write that, then close the output file, etc. Obviously the last output file just copies to the end of the input file. Can you help me with

How to convert docx to PDF in r?

旧时模样 提交于 2019-11-28 06:09:27
问题 I want to ask if it is possible to convert text files such as word document or text document to PDF using R ? I thought of converting it to .rmd and then to PDF using this code require(rmarkdown) my_text <- readLines("C:/.../track.txt") cat(my_text, sep=" \n", file = "my_text.Rmd") render("my_text.Rmd", pdf_document()) But it doesn't work showing this error: Error: Failed to compile my_text.tex. In addition: Warning message: running command '"pdflatex" -halt-on-error -interaction=batchmode

Create a UTF8 file without BOM with Inno Setup (Unicode version)

一笑奈何 提交于 2019-11-28 05:36:56
问题 I have to read and modify some JSON files. The file encoding must be UTF8 without BOM or the JSON file will be not accepted. I tried the following Code: const Utf8Bom = #$EF#$BB#$BF; Utf16BomLE = #$FF#$FE; // little endian // Utf16BomBE = #$FE#$FF; // big endian // Utf16Bom = Utf16BomBE; CP_UTF16 = 1200; CP_UTF8 = 65001; function WideStringToString (const wStr: string; codePage: Word): string; var len: Integer; begin len := WideCharToMultiByte (codePage, 0, wStr, -1, '', 0, 0, 0); if len > 0