text-files

How to remove a line from text file using php without leaving an empty line

假如想象 提交于 2019-12-23 17:42:01
问题 currently I am able to remove a specific line from text file using php. However, after removing that line, there will be an empty line left behind. Is there anyway for me to remove that empty line so that the lines behind can move up? Thank you for your help. 回答1: $DELETE = "the_line_you_want_to_delete"; $data = file("./foo.txt"); $out = array(); foreach($data as $line) { if(trim($line) != $DELETE) { $out[] = $line; } } $fp = fopen("./foo.txt", "w+"); flock($fp, LOCK_EX); foreach($out as

How to read plain text file in kotlin?

谁都会走 提交于 2019-12-23 16:52:18
问题 There may be various way to read plain text file in kotlin. I want know what are the possible ways and how I can use them. 回答1: Using BufferedReader import java.io.File import java.io.BufferedReader fun main(args: Array<String>) { val bufferedReader: BufferedReader = File("example.txt").bufferedReader() val inputString = bufferedReader.use { it.readText() } println(inputString) } Using InputStream Read By Line import java.io.File import java.io.InputStream fun main(args: Array<String>) { val

How do I find a specific string in one of many text .log files using VBA?

旧时模样 提交于 2019-12-23 13:11:28
问题 This is the code I have so far to find all the log files in a folder. But I need to be able to find a specific string in each file, if it is found in one file, stop looking and exit the loop and report back what filename it was in. There seems to be so many different ways to open a file and search it that I do not know which is the best and I do not typically use VBA but it is all I have access to at the moment. On a side note, there would be a max of 36 log files and each file max of 5MB

How to read a Chinese text file from C#?

纵饮孤独 提交于 2019-12-23 12:42:01
问题 How can I read a Chinese text file using C#, my current code can't display the correct characters: try { using (StreamReader sr = new StreamReader(path,System.Text.Encoding.UTF8)) { // This is an arbitrary size for this example. string c = null; while (sr.Peek() >= 0) { c = null; c = sr.ReadLine(); Console.WriteLine(c); } } } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } 回答1: You need to use the right encoding for the file. Do you know what that encoding

Load .txt file from javascript with jquery [closed]

孤街醉人 提交于 2019-12-23 11:56:15
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago . I want to load a local .txt file and work with the content in javascript. My local file is like C:\Users\Who\Desktop\file.txt Thanks 回答1: by default javascript is NOT allowed to access local file system for

Creating new files with Lua I/O functions

这一生的挚爱 提交于 2019-12-23 10:56:45
问题 I'm starting to learn about the io. functions, and am trying to implement them in my code. I've searched for the answer to this and nothing seems to give a clear cut yes or no, or at least I don't see one. I'm hoping someone here will know the answer and be able to help with this. I'm wanting to create a text file that I can write to as time progresses. It'll basically be a log to which I'll be appending lines of output. Apparently io.open("textfile.txt") does not create the file, or so it

Reading text values into matlab variables from ASCII files

*爱你&永不变心* 提交于 2019-12-23 08:54:29
问题 Consider the following file var1 var2 variable3 1 2 3 11 22 33 I would like to load the numbers into a matrix, and the column titles into a variable that would be equivalent to: variable_names = char('var1', 'var2', 'variable3'); I don't mind to split the names and the numbers in two files, however preparing matlab code files and eval'ing them is not an option. Note that there can be an arbitrary number of variables (columns) 回答1: I suggest importdata for operations like this: d = importdata(

How do you extract email addresses from the 'To' field in outlook?

一曲冷凌霜 提交于 2019-12-23 08:54:16
问题 I have been using VBA to some degree, using this code: Sub ExtractEmail() Dim OlApp As Outlook.Application Dim Mailobject As Object Dim Email As String Dim NS As NameSpace Dim Folder As MAPIFolder Set OlApp = CreateObject("Outlook.Application") ' Setup Namespace Set NS = ThisOutlookSession.Session ' Display select folder dialog Set Folder = NS.PickFolder ' Create Text File Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:\mydocuments\emailss.txt", True) ' loop

Creating/editing textfile through VB.NET

痴心易碎 提交于 2019-12-23 08:12:42
问题 How do I code the algorithm below in VB.NET? Procedure logfile() { if "C:\textfile.txt"=exist then open the textfile; else create the textfile; end if go to the end of the textfile; write new line in the textfile; save; close; } 回答1: Dim FILE_NAME As String = "C:\textfile.txt" Dim i As Integer Dim aryText(4) As String aryText(0) = "Mary WriteLine" aryText(1) = "Had" aryText(2) = "Another" aryText(3) = "Little" aryText(4) = "One" Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True) For

Creating/editing textfile through VB.NET

人走茶凉 提交于 2019-12-23 08:12:14
问题 How do I code the algorithm below in VB.NET? Procedure logfile() { if "C:\textfile.txt"=exist then open the textfile; else create the textfile; end if go to the end of the textfile; write new line in the textfile; save; close; } 回答1: Dim FILE_NAME As String = "C:\textfile.txt" Dim i As Integer Dim aryText(4) As String aryText(0) = "Mary WriteLine" aryText(1) = "Had" aryText(2) = "Another" aryText(3) = "Little" aryText(4) = "One" Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True) For