|
Hi, I would like to parse the content of a textarea in my django view, line by line (or get a specific line number). Thanks
Started by djibril on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
For line in text_area_value.split('\n'): # do something with line
or if you want a specific number (3 in this example - which is the 4th line, counting the "human" way):
lines = text_area_value.split.
|
|
Hello,
I have an array of bytes (say byte[] data), which contains text with custom line delimeters, for example: "\r\n" (CRLF "\x0D\x0A"), "\r", "\n", "\x0D\x0A\x0D" or even "@".
At the moment I'm going to use the following solution:
Normalize line breaks...
Started by Alpha Sisyphus on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Foreach (string delim in DelimiterStrings) text = text.Replace(delim, "\n"); foreach (string line.
|
|
Not a dup of http://stackoverflow.com/questions/391710/in-vim-what-is-the-simplest-way-to-join-all-lines-in-a-file-into-a-single-line , as I specifically mean to use the gq reformating functionality.
I used to write latex in vim using 80 character textwidth...
Started by Paul Biggar on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Adjust tw to your needs..
Why don't you just "J" the lines after you select them?
If you don't like "J" as depesz suggested then do
:set tw=9999
Then do 'gq'.
|
Ask your Facebook Friends
|
I'm using python -c to execute a one-liner loop, i.e.:
$ python -c "for r in range(10): print 'rob'"
this works fine. However, if I import a module before the for loop, I get a syntax error:
$ python -c "import sys; for r in range(10): print 'rob'" File...
Answer Snippets (Read the full thread at stackoverflow):
Just use return and type it on the next line:
user@host:~$ python -c "import sys > for r.
|
|
I want to iterate over cin, line by line, addressing each line as a std::string. Which is better:
string line; while (getline(cin, line)) { // process line }
or
for (string line; getline(cin, line); ) { // process line }
? What is the normal way to do...
Started by cppLearner on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
First up, a really simple class that acts as a string proxy:
class line { std::string data; public: friend std::istream &operator....
line in a container:
vector<string> lines((LineInputIterator<>(stream alternative methods.
|
|
Suppose to feed the filter standard input with these line:
line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10
It would be nicer if someone tell me how to write a script that prints only every 4 lines, in the case of the example input...
Started by Andrea Francia on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Awk '{ if ((NR-1) %4 ==0) print}'
awk 'NR%4 == 1 {print}'</etc/hosts
Replace 4 by whatever value you want of course. .
Yes | cat -n | head -10 | awk 'NR % 4 == 1' 1 y 5 y 9 y
That is, your answer is " awk 'NR % 4 == 1' " .
|
|
I'm parsing a large file in Perl line-by-line (terminated by \n), but when I reach a certain keyword, say "TARGET", I need to grab all the lines between TARGET and the next completely empty line.
So, given a segment of a file:
Line 1
Line 2
Line 3
Line...
Started by ImSleeping on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Ugly auto-generated code, and assuming you just want lines between TARGET and the next empty line)
The short answer: line delimiter in perl is $/ , so when you hit TARGET, you can set $/ to "\n\n" , read the next "line", ....
|
|
I have a multi-line string literal that I want to do an operation on each line, like so.
inputString = """Line 1 Line 2 Line 3"""
I want to do something like the following.
for line in inputString: doStuff()
Started by bradtgmurray on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Like the others said:
inputString.split('\n'....
For line in split(inputString, "\n"): doStuff()
inputString.splitlines()
Will give you an array with each item, the splilines() function is designed to split each line into an array element.
|
|
Say I have a super long line in the VIM editor (say around 300+ characters). How would I break that up into multiple lines so that the word boundaries roughly break at 80 characters?
Example:
This is a really long line This is a really long line This ...
Started by j0rd4n on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
HTH
'Avahappy setting textwidth (tw) will....
Then hitting q and CR will break the line up into chunks on the word boundary.
Which says:
start a 0th position of line, move to 80th char to the right, go to beginning of next word for that char.
|
|
In vim when my cursor is on the first line I can press:
100dd
to delete the first 100 lines.
But how do I delete all lines except the last 100 lines?
Started by Edward Tanguay on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
$ is the last line, and....
In normal mode:
G100kdgg
In other words:
G -> go to last line 100k -> go up 100 lines dgg command of ex mode deletes lines, specified as a single line number, or a range of lines.
|