Get each line from textarea

You will want to look into the nl2br() function along with the trim(). The nl2br() will insert <br /> before the newline character (\n) and the trim() will remove any ending \n or whitespace characters. $text = trim($_POST[‘textareaname’]); // remove the last \n or whitespace character $text = nl2br($text); // insert <br /> before \n … Read more

clearRect function doesn’t clear the canvas

You should use “beginPath()“. That is it. function lineDraw() { var canvas=document.getElementById(“myCanvas”); var context=canvas.getContext(“2d”); context.clearRect(0, 0, context.width,context.height); context.beginPath();//ADD THIS LINE!<<<<<<<<<<<<< context.moveTo(0,0); context.lineTo(event.clientX,event.clientY); context.stroke(); }

Add each array element to the lines of a file in ruby

Either use Array#each to iterate over your array and call IO#puts to write each element to the file (puts adds a record separator, typically a newline character): File.open(“test.txt”, “w+”) do |f| a.each { |element| f.puts(element) } end Or pass the whole array to puts: File.open(“test.txt”, “w+”) do |f| f.puts(a) end From the documentation: If called … Read more

Process very large (>20GB) text file line by line

It’s more idiomatic to write your code like this def ProcessLargeTextFile(): with open(“filepath”, “r”) as r, open(“outfilepath”, “w”) as w: for line in r: x, y, z = line.split(‘ ‘)[:3] w.write(line.replace(x,x[:-3]).replace(y,y[:-3]).replace(z,z[:-3])) The main saving here is to just do the split once, but if the CPU is not being taxed, this is likely to make … Read more

Is there a C++ iterator that can iterate over a file line by line?

EDIT: This same trick was already posted by someone else in a previous thread. It is easy to have std::istream_iterator do what you want: namespace detail { class Line : std::string { friend std::istream & operator>>(std::istream & is, Line & line) { return std::getline(is, line); } }; } template<class OutIt> void read_lines(std::istream& is, OutIt dest) … Read more

Reading a file line by line in C#

You can write a LINQ-based line reader pretty easily using an iterator block: static IEnumerable<SomeType> ReadFrom(string file) { string line; using(var reader = File.OpenText(file)) { while((line = reader.ReadLine()) != null) { SomeType newRecord = /* parse line */ yield return newRecord; } } } or to make Jon happy: static IEnumerable<string> ReadFrom(string file) { string … Read more

count lines in a PHP project [closed]

On a POSIX operating system (e.g. Linux or OS X) you can write the following into your Bash shell: wc -l `find . -iname “*.php”` This will count the lines in all php-files in the current directory and also subdirectories. (Note that those single ‘quotes’ are backticks, not actual single quotes)