How to read a text file for a specific word in lines and write the entire lines to another text file?
By : Tony
Date : March 29 2020, 07:55 AM
will help you If all you need file2 for is to get the build number, you don't have to create it at all: code :
protected override void Execute(CodeActivityContext context)
{
// Obtain the runtime value of the Text input argument
string TextFileName = context.GetValue(this.TextFileName);
string TextFilePath = TextFileName;
string number = null;
var splitChars = new[]{ ' ' };
foreach (var line in File.ReadLines(TextFilePath))
{
var values = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries).ToArray();
if (values.Length < 3)
continue;
buildNumber = (values[1] == "Rel" ? values[0] : buildNumber);
}
context.SetValue<string>(this.setBuildNumber, number);
}
|
How to read text file lines after Specific lines using StreamReader
By : 王富贵
Date : March 29 2020, 07:55 AM
hope this fix your issue There's a much faster way to do this that doesn't require you to read the entire file in order to get to the point where you left off. The key is to keep track of the file's length. Then you open the file as a FileStream, position to the previous length (i.e. the end of where you read before), and then create a StreamReader. So it looks like this: code :
long previousLength = 0;
using (var fs = File.OpenRead(FileToCopy))
{
// position to just beyond where you read before
fs.Position = previousLength;
// and update the length for next time
previousLength = fs.Length;
// now open a StreamReader and read
using (var sr = new StreamReader(fs))
{
while (!sr.EndOfStream)
{
var line = sr.ReadLine();
// do something with the line
}
}
}
|
How to read in specific lines from file
By : Elizabeth Stevens
Date : March 29 2020, 07:55 AM
To fix the issue you can do I looked at the FASTA spec on Wikipedia. Looks like long sequences can span multiple lines. In that case, I assume you would want the lines concatenated. It also says that the informational lines start with a ">" but could also start with a ";". Assuming that the file is small enough to be read entirely into memory, I came up with the following using regular expressions: code :
import re
regex = re.compile(r"[;>](?P<description>[^\n]*)\n(?P<sequence>[^;>]+)")
with open("datafile.txt","r") as f:
sequences = regex.findall(f.read())
for i, info in enumerate(sequences):
description, sequence = info
print("sequence%d: %s" % (i, sequence.replace("\n","")))
|
Python: Read in specific lines from a file and replace a specific character on those lines and save file
By : mr April
Date : March 29 2020, 07:55 AM
it should still fix some issue You should change the if index == 2 statement to be if index % 4 == 2, and remove the index=index+4 line.
|
How do I read specific lines from a txt file- Qt?
By : mitchelljs
Date : October 08 2020, 04:00 AM
it fixes the issue According to me, you cannot go to a specific line without knowing the line(s) size(s) since seek() can only move the cursor into a specific position value. The only solution I can see is the one suggested by @Botje. code :
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
int nb_line(0);
while(!stream.atEnd())
{
line = stream.readLine();
if((nb_line % 5) == 1)
ui->ServersNames->addItem(line);
++nb_line;
}
file.close();
}
|