w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to add a break to a line while writing to a text file
Your underlying QIODevice (the file) is not really working in text mode. Use QIODevice::Text when opening the file that is used with the stream QFile file( filename , QIODevice::Text ); ... QTextStream stream( &file); For a text stream, both " " and ' ' should work. You may opt for std::endl (or, more precisely, its counterpart in Qt) instead, but this is not really necessary. " " and ' ' will produce proper result regardless of the OS, assuming your output stream is indeed a text stream, and assuming that your generate file on the same platform that you use to inspect it. (The remarks asserting that " " must be used on Windows are incorrect.) An example of a situation when you indeed will have to use " " is when you are trying to generate a Windows text file on a POSIX system.

Categories : C++

PHPWord how to add text break / new line while in a text run
I'm afraid that this will not be possible with current version. I don't have deep understanding of this library, but from looking at the code, I found out that the textRun class consist only of addText and addLink methods. But I also need this feature along with several others, so I'm going to write it myself and create a pull request to get it included in the next release (if there will be any). Basically it can be done by modifying the textRun class, adding an addLineBreak method (similar way as it is in the section class) and then modify class Base.php to create proper elements in final document. In Docx xml, those line brakes are similar to the html br tag, but previous text must be closed and reopened after using break like this: <w:r> <w:t>This is</w:t> <

Categories : PHP

On css: if text line is break show dots
Are you talking about an ellipsis? Add this to your CSS text-overflow: ellipsis; white-space: nowrap; Fiddle: http://jsfiddle.net/5UPRU/7/

Categories : CSS

break long text/string to a new line
See wordwrap. Something like: echo wordwrap($yourString, 20, '<br>'); But it might be a better idea to do this with CSS (word-wrap: break-word)

Categories : PHP

Vba excel. Find text insie cell with line break
If the text was entered in the cell useing the Alt+Enter method you can use this in your VBA: " & Chr(10) & " Here is the .Find method that I have used. Private Sub CommandButton1_Click() Set RngClosedDate = Range("A1:Z10").Find(What:="Closed" & Chr(10) & "(Date)", LookAt:=xlWhole, LookIn:=xlValues) ' If the text that is searched for from the line above is not found then a message box is displayed and sub function is exitied If RngClosedDate Is Nothing Then MsgBox "Closed (Date) Column Header Not found. Cannot sort or format records." Exit Sub End If End Sub

Categories : Vba

how to break line in jsp from class file in struts
Not sure but you can try with filter <bean:write name="row" property="campaignPeriod" filter="false"/> this is what doc say about filter if this attribute is set to true, the rendered property value will be filtered for characters that are sensitive in HTML, and any such characters will be replaced by their entity equivalents.

Categories : Java

Break line automatically when user input long text without adding white-space
If you're down with CSS3 you may try the 'word-break' property. To see a demo: http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-break

Categories : PHP

Outputting as a line break when returning string as a file
So change the to the newline sequence you want. Probably the easiest way, assuming that your text is a string, is: text = text.Replace(" ", Environment.Newline);

Categories : C#

Break down text file in bash
This worked for me: IFS=$' ' curfile="" content=($(< file.txt)) for ((idx = 0; idx < ${#content[@]}; idx++)); do if [[ ${content[idx]} =~ ^.*chrom=(\b.*?\b) .*$ ]]; then curfile="${BASH_REMATCH[1]}.txt" rm -rf ${curfile} elif [ -n "${curfile}" ]; then echo ${content[idx]} >> ${curfile} fi done

Categories : Regex

Break down sections in a text file using vbscript
Simple solution: Set fso = CreateObject("Scripting.FileSystemObject") Set re = New RegExp re.Pattern = "s+" re.Global = True Set f = fso.OpenTextFile("C:yourinput.txt") Do Until f.AtEndOfStream tokens = Split(Trim(re.Replace(f.ReadLine, " "))) WScript.Echo "C:" & tokens(1) & tokens(0) Loop f.Close

Categories : Vbscript

Double Linked List vs Array in Text Editors
Transferring comments into an answer since no-one else is chipping in. Why not use a (doubly linked) list of strings, where each item in the list is a line, so you can call printw() once per line as with arrays? You'd also dramatically reduce the storage requirement; on a 64-bit machine, a doubly linked list of single characters would likely use 24 bytes per character, which is quite a high overhead. I actually just started doing that. It does seem like a pretty decent compromise (I have a hunch that it's what nano uses). I'm probably going to delete this question, because I think that's my solution I'll be working with. Also, is it a bad idea to use realloc() at every insertion/removal? I'd probably design the list nodes along the lines of: struct Line { struct Line *next;

Categories : C

On press enter key in textarea prevent line break and remove the text in the textarea
Add e.preventDefault(); to the end of your function. https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault

Categories : Javascript

Break a text file into smaller chunks in python
You can chunk by actual bytesize: def chunk(fname): with open(fname, 'rb') as fin: return list(iter(lambda: fin.read(4096), '')) Note that you might as well yield each chunk instead of building a list, and let the caller decide if it wants to build a list instead. for chunk in iter(lambda: fin.read(4096), ''): yield chunk

Categories : Python

Change encoding of text file (shell archive or script for antique kernel text to ASCII text, with CRLF, LF line terminators)
Unix uses a single character for line termination. If you want to convert your file with CRLF to single character termination, you can do the following: sed -e 's/<CTRL-V><CTRL_M>//' filename where <CTRL-V> is the Control key pressed with V (do not include < and > characters in the command.

Categories : Bash

Extract a numeric substring and another line as variables from multi-line text file
You could use the following regex for the second line: ^.*(d{6})[^d].*$ Here, the first named sub-group would denote the digits of interest. For example, using Notepad++, Orginal text: Replace options: Resulting text: The regex should remain more or less the same across environments. You might need to simply change the way the named subexpression ($1 here) is referenced.

Categories : Regex

Objective C - Create text file to read and write line by line in Cocoa
Well, to create a file, just use [[NSFileManager defaultManager] createFileAtPath:@"Your/Path" contents:nil attributes:nil]; This creates an empty file, which you can write to or read from. To write text (or XML), just use NSString's writeToFile:atomically:encoding:error: method like this NSString *str = //Your text or XML [str writeToFile:"Your/Path" atomically:YES encoding:NSUTF8StringEncoding error:nil]; To read from a file, just make an NSString with the contents of that file NSString *contents = [NSString stringWithContentsOfFile:@"Your/Path"]; or, if it does not contain a string, get an NSData object from the file NSData *contents = [NSData dataWithContentsOfFile:@"Your/Path"];

Categories : Objective C

sending text file from server to client line by line in winsocks
You need to also send a newline. getline reads all characters until a newline, but doesn't store the newline in the string. So when you send the string, it doesn't have a newline. You can either send a " " on its own, but probably better to add a newline to the existing string. E.g. : stringToUpper(STRING); STRING += " "; ...

Categories : C++

How to read data from Excel and write it to text file line by line?
You should open the output.txt file with append mode: file = open("Output.txt", "a") Also, you should do this before entering the loop, and it should be closed after that loop. Update: In cases like this one, you could use with instead of closing the file handle at the end. Also including the good suggestion made by @Josh in his own answer, the code could be this: import xlrd import os.path wb = xlrd.open_workbook(os.path.join('D:TRB 2014 Data','SPS1 demo data.xlsx')) wb.sheet_names() sh = wb.sheet_by_index(0) i = 1 with open("Output.txt", "a") as my_file: while sh.cell(i,11).value != 0: Load = sh.cell(i,11).value all_d = sh.col_values(i, 13, 19) DB1 = Load + " " + (" ".join(all_d)) my_file.write(DB1 + ' ') i += 1

Categories : Python

Assigning variables to values in a text file with 3 columns, line by line
while read x y z; do echo x=$x y=$y z=$z done < input.txt The above requires that none of your columns contain any whitespace. EDIT: In response to comments, here is one technique to handle numbering the lines: nl -ba < input.txt | while read line x y z rest; do ~/data/standard/MNI152_T1_2mm -mul 0 -add 1 -roi $x 1 $y 1 $z 1 0 1 point -odt float > NewFile$line done

Categories : Bash

Iterating though a text file in Java so that each line has information about that line
I cleaned up your code a little bit. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Palindrome { int charCount = 0; int totalWordCount = 0; public static String isPalindrome(String str) { if(str.equals(new StringBuffer().append(str).reverse().toString())) { return "a"; } else { return "not a"; } } public static int getNumberOfWords(String str) { return str.isEmpty() ? 0 : str.split("\s+").length; } public void process(File file) { try { Scanner sc = new Scanner(file); int i = 0; while(sc.hasNextLine()) { i++; String line = sc.nextLine(); int wordCount =

Categories : Java

Compare a text file line by line with a dynamic variable
If I understand the question correctly, this is what you need: File insert = new File("sample.txt"); BufferedReader br = new BufferedReader(new FileReader(insert)); String strLine; Boolean hasLine = false; while ((strLine = br.readLine()) != null) { if(strLine.equals(field)) { hasLine = true; break; } } br.close(); if (!hasLine) { FileWriter fw = new FileWriter(insert, true); BufferedWriter bw = new BufferedWriter(fw); bw.append(field + " "); // assumes field does not already have a newline bw.flush(); bw.close(); } Notice the break;. This will discontinue the while loop, since you already have the answer to what you are looking for. Your original code was doing: for every line: Do I equal field? Yes: goto next line No: append f

Categories : Java

How to delete a line from a text file using the line number in python
You start counting at one, but python indices are always zero-based. Start your line count at zero: for num, line in enumerate(myFile): # default is to start at 0 or subtract one from num, deleting from lines (not line): del lines[num - 1] Note that in order for your .readlines() call to return any lines, you need to either re-open the file first, or seek to the start: myFile.seek(0)

Categories : Python

reading a tab delimited text file line by line get data after in vb.net
RichTextBox_WD.Text = String.Join(vbCrLf, File.ReadLines(vcFile).Select(Function(line) Dim format = "RECEIVED ON: {0} FROM: {1} AMOUNT {2}" Dim fields = line.Split(vbTab) Return String.Format(format, fields(0), fields(1), fields(2)) End Function) I prefer to create a Joined extension method on IEnumerable<T> which wraps String.Join (taking a delimiter and an optional transformation delegate), and a Formatted extension method on String which wraps String.Format: RichTextBox_WD.Text = Fil

Categories : Vb.Net

write text file line by line python
If you have the Names and Locations as a list, you can do this: data = [('James','Germany'), ('Gail','US'), ('Merkel','Poland')] with open('output', 'w') as f: for name,place in data: f.write("Name=%s Location=%s " % (name, place))

Categories : Python

Node.js: Inserting a line after a particular line in a text file?
Callback in for loop is not a good idea. Try this code - fs.readFile('nginx.conf', function(err, data) { if(err) throw err; //data = data.toString(); var array = data.toString().split(" "); array[4] ='deny '+cli.getValue(options.ip)+':'+cli.getValue(options.port); for(i=0;i<array.length;i++) { fs.appendFileSync('nginx1.conf', array[i]+' '); } });

Categories : Javascript

write a text file in Python, line by line
You have print new_str for every line in test.txt. But you only write one line to the file after the loop. Changing the code to write after each print: outf = open('result.txt', 'w') for line in fileinput.input("test.txt"): new_str = re.sub('[^a-zA-Z0-9 .]'," ", line) print new_str outf.write(new_str + ' ') outf.close() will do what you want.

Categories : Python

Enable Break Line or New Line in Textarea when press enter
Newlines in textarea's are saved into the database by default. To generate them as Html BR codes, use nl2br($yourTextVariable) $yourTextVariable will be the variable you fetch from database. so use it like this : <?php echo nl2br($yourTextVariable); ?> This transforms newline to <br />

Categories : Misc

Does PHP offer file concurrency in this scenario?
Basically, you should lock the file while writing or reading. At least, it guarantees that there is no problem. It is the way of good programming!. The example is shown below. <?php $fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, LOCK_EX)) { // do an exclusive lock fwrite($fp, "Write something here "); flock($fp, LOCK_UN); // release the lock } else { echo "Couldn't lock the file !"; } fclose($fp); ?> More information

Categories : PHP

How can I offer to upload a file without making it required
if($_FILES['userfile']['error'] == UPLOAD_ERR_OK) { // A file was selected and uploaded to the server for further processing } Other possible values for the error field if you need to give more extensive feedback.

Categories : Codeigniter

How to append text in every line of a file except for the first line
How about: sed -e '2,$ s/$/|Paris/' < abc.txt And including the header: sed -e '1 s/$/|Place/' -e '2,$ s/$/|Paris/' < abc.txt For the last line, you must have an extra blank line in the file. So, delete all lines containing nothing but zero or more spaces: sed -e '/^ *$/ d' -e '1 s/$/|Place/' -e '2,$ s/$/|Paris/' < abc.txt

Categories : File

parsing a text file with first line all 1's and second line all 2's
You can create a vector of vectors as vector<vector<string>> VEC; And keep on adding words to VEC[0] for the first line and then increment the counter as you encounter a newline character to point to VEC[1] and so on.

Categories : C++

read a text file line by line
It's all built into StreamReader: using (var sr = new StreamReader(myFile)) { string line; while ((line = sr.ReadLine()) != null) { // line is the text line } }

Categories : File

How do I replace a certain line on a text file with diferent text?
You seem to be confusing static and non-static methods: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { System::String^ txtfile = L"C:\Users\acer\Desktop\aaa.txt"; array<System::String^>^ lineArray = System::IO::File::ReadAllLines(txtfile); System::Collections::Generic::List<System::String^>^ lineList; lineList = gcnew System::Collections::Generic::List<System::String^>(lineArray); lineList->RemoveAt(6); System::IO::File::WriteAllLines(txtfile, fileList->ToArray()); }

Categories : C++

Delete/edit/add a line of text from a text file
I would recommend a Streamreader and ReadLine() for reading all lines and a List for saving them. So the code for the reading + saving would be: Dim lineList As New List(Of String)() Dim sr As StreamReader = New StreamReader(path) Do While sr.Peek() >= 0 lineList.add(sr.ReadLine()) Loop Then add some labels (with the text) to your form: For i as Integer = 0 to lineList.Count - 1 Dim Label as New Label lineLabel.Text = lineList.Item(i) lineLabel.Location = New Point(0, 50 * i) 'you can change the 50 to whatever value you want Me.Controls.Add(Label) AddHandler Label.Click, AddressOf Me.Label_Click 'here we add a handler for the label-clicks Next The handler will look like this then: Private Sub Label_Click(ByVal sender As System.Object, ByVa

Categories : Vb.Net

How to update the first line of text in a text file in VB.NET
In C#.Net: var filepath = "/file/path"; var list = File.ReadAllLines(filepath).ToList(); list.Insert(0, String.Format("Records in this file: {0}", list.Count)); File.WriteAllLines(filepath, list); In VB.Net (I think, i dont really use VB) Dim filepath = "/file/path" Dim list = File.ReadAllLines(filepath).ToList() list.Insert(0, [String].Format("Records in this file: {0}", list.Count)) File.WriteAllLines(filepath, list)

Categories : Dotnet

Find the last line in text file and select the first 10 char and print to a new file?
ifstream file; string filename="D:\example.txt"; file.open(filename.c_str()); string line; while(getline(file,line)); Now you have your last line in the string line now send the 10 chars of line to an output file. line.substr(0,10) will fetch the first ten chars.

Categories : C++

batch file to overwrite a line in a text file
These links will help you How to replace BatchSubstitute

Categories : File

reading file line by line , modify the line and write this line on same file. Python
Because you've used .split on the line, you're working with a list of strings. While a string is conceptually just a list of characters, it's still not a list of strings. Try using the .join method of a string to join your array before you write it out, for example: ''.join(["one, two"]) == "onetwo"

Categories : Python

Read text file in Perl word by word instead of line by line
Instead of reading it in one fell swoop, try the line-by-line approach which is easier on your machine's memory usage too (although 300 KB isn't too large for modern computers). use strict; use warnings; my @words; open (my $inFile, '<', 'tagged.txt') or die $!; while (<$inFile>) { chomp; @words = split(' '); foreach my $word (@words) { # process } } close ($inFile);

Categories : Perl

Line break in PHP
doesn't work in HTML. If you view source of the document you will however see the line breaks. Use html markup like Test line break<br /> <p>paragraph</p> <p>paragraph</p>

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.