text-files

remove new line characters from txt file using php

为君一笑 提交于 2019-11-27 23:52:35
I have txt file its content like this Hello World John play football I want to delete the new line character when reading this text file, but I don't know how it look like the file .txt and its encoding is utf-8 Just use file function with FILE_IGNORE_NEW_LINES flag. The file reads a whole file and returns an array contains all of the file lines. Each line contains new line character at their end as default, but we can enforce trimming by FILE_IGNORE_NEW_LINES flag. So it will be simply: $lines = file('file.txt', FILE_IGNORE_NEW_LINES); The result should be: var_dump($lines); array(5) { [0] =>

Notepad++ can recognize encoding?

空扰寡人 提交于 2019-11-27 23:39:12
I created file with UTF-8 encoded content (using PHP fputcsv). When I open this file in Notepad++ - characters are wrong (Notepad++ starts with ANSI encoding). When I set Format->"Encode in UTF-8" from menu - everything is fine. Im worrying, that Notepad++ can recognize encoding somehow, and maybe something is wrong with my file created with fputcsv ? First byte or something? Chamila Chulatunga Automatically detecting an encoding is not something that can be done accurately. It's pretty much essential that the encoding be specified explicitly. It can be guessed in some cases, but even then not

Easiest way to read text file which is locked by another application

假如想象 提交于 2019-11-27 22:55:37
问题 I've been using File.ReadAllText() to open a CSV file, but every time I forget to close the file in Excel, the application throws an exception because it can't get access to the file. (Seems crazy to me, I mean the READ in ReadAllText seems pretty clear) I know that there is File.Open with all the bells and whistles, but is there an 'intermediate' method which doesn't involve messing around with buffers and char arrays? 回答1: I think you just want the following: using (var fileStream = new

Creating, writing and editing same text file in java

末鹿安然 提交于 2019-11-27 22:25:30
问题 Let's say I have the following code: import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class EditFile { public static void main(String[] args) { try{ String verify, putData; File file = new File("file.txt"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write("Some text here for a reason"); bw.flush(); bw.close()

Read lines from a text file but skip the first two lines

帅比萌擦擦* 提交于 2019-11-27 22:11:11
I've got this macro code in Microsoft Office Word 2003 which reads the lines of a text file. The lines each represent a string value that I need to use later in the code. However, the first two lines of the text file contains some stuff that I don't need. How can I modify the code so that it skips the two first lines? The "Intellisense" within the VBA editor in Word sucks hard btw.. Anyway, the code looks something like this Dim sFileName As String Dim iFileNum As Integer Dim sBuf As String Dim Fields as String sFileName = "c:\fields.ini" ''//Does the file exist? If Len(Dir$(sFileName)) = 0

Get the number of lines in a text file using R

余生颓废 提交于 2019-11-27 22:08:45
Is there a way to get the number of lines in a file without importing it? So far this is what I am doing myfiles <- list.files(pattern="*.dat") myfilesContent <- lapply(myfiles, read.delim, header=F, quote="\"") for (i in 1:length(myfiles)){ test[[i]] <- length(myfilesContent[[i]]$V1) } but is too time consuming since each file is quite big. If you: still want to avoid the system call that a system2("wc"… will cause are on BSD/Linux or OS X (I didn't test the following on Windows) don't mind a using a full filename path are comfortable using the inline package then the following should be

How to read large text file on windows? [closed]

本小妞迷上赌 提交于 2019-11-27 19:56:37
问题 I have a large server log file (~750 MB) which I can't open with either Notepad or Notepad++ (they both say the file is too large). Can anyone suggest a program (for Windows) that will only read a small part of the file into memory at a time? Or do I need to write my own app to parse this file? 回答1: try this... Large Text File Viewer By the way, it is free :) But, I think you should ask this on serverfault.com instead 回答2: If all you need is a tool for reading, then this thing will open the

J2ME/Blackberry - how to read/write text file?

女生的网名这么多〃 提交于 2019-11-27 19:30:16
please give me a sample code for read/write text file in blackberry application. Maksym Gontar My code snippet for string read/write files: private String readTextFile(String fName) { String result = null; FileConnection fconn = null; DataInputStream is = null; try { fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE); is = fconn.openDataInputStream(); byte[] data = IOUtilities.streamToBytes(is); result = new String(data); } catch (IOException e) { System.out.println(e.getMessage()); } finally { try { if (null != is) is.close(); if (null != fconn) fconn.close(); } catch

Copying from one text file to another using Python

a 夏天 提交于 2019-11-27 19:05:08
I would like to copy certain lines of text from one text file to another. In my current script when I search for a string it copies everything afterwards, how can I copy just a certain part of the text? E.g. only copy lines when it has "tests/file/myword" in it? current code: #!/usr/bin/env python f = open('list1.txt') f1 = open('output.txt', 'a') doIHaveToCopyTheLine=False for line in f.readlines(): if 'tests/file/myword' in line: doIHaveToCopyTheLine=True if doIHaveToCopyTheLine: f1.write(line) f1.close() f.close() The oneliner: open("out1.txt", "w").writelines([l for l in open("in.txt")

Convert Word doc or docx files into text files?

谁说胖子不能爱 提交于 2019-11-27 18:52:42
I need a way to convert .doc or .docx extensions to .txt without installing anything. I also don't want to have to manually open Word to do this obviously. As long as it's running on auto. I was thinking that either Perl or VBA could do the trick, but I can't find anything online for either. Any suggestions? Note that an excellent source of information for Microsoft Office applications is the Object Browser . You can access it via Tools → Macro → Visual Basic Editor . Once you are in the editor, hit F2 to browse the interfaces, methods, and properties provided by Microsoft Office applications.