newline

Java Scanner newline parsing with regex (Bug?)

I'm developing a syntax analyzer by hand in Java, and I'd like to use regex's to parse the various token types. The problem is that I'd also like to be able to accurately report the current line number, if the input doesn't conform to the syntax. Long story short, I've run into a problem when I try to actually match a newline with the S...

Emacs: add do/while & if/else as exceptions to electric c mode (})

When c-auto-newline is set to non-nil, it re-indents the current line and inserts a carriage return and then indents the new line. However. I'm using 1TBS indent-style (with 4 space indents), which means if/else statements are made like this: if (n == 1) { exit(EXIT_SUCCESS); } else { perror("n"); } Also, I write do/while writ...

How to read input until the user enters ^X

I am creating an interpreter for my esolang, and I need the user to enter some text which then will be interpreted as an INTERCAL program. I want the user to enter text, which may contain any character including newlines, until the user presses ^X (Ctrl-X), like this: Enter your code followed by ^X: Bla Blablabla Bla^X Thank you for ent...

How can Perl's print add a newline by default?

In Perl most of my print statements take the form print "hello." . "\n"; Is there a nice way to avoid keeping all the pesky "\n"s lying around? I know I could make a new function such as myprint that automatically appends \n, but it would be nice if I could override the existing print. ...

How to add custom line endings in text file (e.g. I want to add a line ending after all periods)

I have a bunch of text files where I want to add a line ending after each period. I'm wondering if there is a way to do this by doing replacing all periods with a \n\n, assuming I have the right encoding (unix). Anyone know how I would do this? Replace .'s with .\n\n and then save as a different file? Thanks! ...

UNIX: Replace Newline w/ Colon, Preserving Newline Before EOF

I have a text file ("INPUT.txt") of the format: A<LF> B<LF> C<LF> D<LF> X<LF> Y<LF> Z<LF> <EOF> which I need to reformat to: A:B:C:D:X:Y:Z<LF> <EOF> I know you can do this with 'sed'. There's a billion google hits for doing this with 'sed'. But I'm trying to emphasis readability, simplicity, and using the correct tool for the corre...

How many bytes is \n\r?

I have a .net app that is trying to ftp a file and we're ending up with 1 extra byte per line. My Line Separatro is Environment.NewLine which I beleive transaltes into \n\r. How many bytes is that? ...

How to handle this string in json?

I am storing a multiline textbox value in my db table... When i converted this value to json it gives me an error Error: unterminated string literal... My sample data was , I am fetching the row to my datatable and then converting it to json, public string GetJSONString(DataTable table) { StringBuilder headStrBuilder = ...

KEY_ENTER vs '\n'?

When I'm using PDcurses and I try to have a while loop exit when the enter key is pressed with while(key != KEY_ENTER), the while loop never exits. However, when I try to have the same loop exit with while((char)key != '\n'), it exits successfully whenever I pressed enter. Why does '\n' work and not KEY_ENTER? btw, key is an int and I ...

How to query an input in Python without outputting a new line

The title describes the question pretty much. ...

PHP Linefeeds (\n) Not Working

For some reason I can't use \n to create a linefeed when outputting to a file with PHP. It just writes "\n" to the file. I've tried using "\\n" as well, where it just writes "\n" (as expected). But I can't for the life of me figure out why adding \n to my strings isn't creating new lines. I've also tried \r\n but it just appends "\r\...

How to identify/handle text file newlines in Java?

Hi Everyone! I get files in different formats coming from different systems that I need to import into our database. Part of the import process it to check the line length to make sure the format is correct. We seem to be having issues with files coming from UNIX systems where one character is added. I suspect this is due to the return ...

PHP New Line will not work

Hi I am trying to create some code that first reads the existing contents of the file in and then adds the new line of code on a new line but the code i am using just adds it on the new text on to the already existing line instead of the new line... Here is the code i am using: <?php $id = $_GET['id']; $userfile = "user1.txt"; $fo = ...

newline statment does not works in Log4Net under Vista Guest account

Hi I'm using Log4Net (1.2.10.0) for logging in my application. It's working fine - till I run it on Vista SP2 under Guest user. The log file does not contains a newline characters - all log is a single line. This is not happen when I run the application as regular or admin user. Only in case of built-in guest account. Any ideas? The ...

How to check for and remove a newline (\n) in the first line of a text field in actionscript?

In the script, sometimes a newline is added in the beginning of the text field (am using a textArea in adobe flex 3), and later on that newline might need to be removed (after other text has been added). I was wondering how to check if there is a newline at the beginning of the text field and then how to remove it. Thanks in advance. ...

How can I put text from a multi-line text box into one string?

Dear reader, I'm faced with a bit of an issue. The scenario is that I have a multi-line text box and I want to put all that text into one single string, without any new lines in it. This is what I have at the moment: string[] values = tbxValueList.Text.Split('\n'); foreach (string value in values...

Writing a new line to file in PHP

My code: $i = 0; $file = fopen('ids.txt', 'w'); foreach ($gemList as $gem) { fwrite($file, $gem->getAttribute('id') . '\n'); $gemIDs[$i] = $gem->getAttribute('id'); $i++; } fclose($file); For some reason, it's writing \n as a string, so the file looks like this: 40119\n40122\n40120\n42155\n36925\n45881\n42145\n45880 Fro...

Formatting populated textarea, carriage returns, newlines, and HAML

When i populate a textarea with text using \r\n (carriage return - newline) the text is formatted improperly [UPDATE: \r\n is what is generated when filling out a textarea, i'm simply pulling from a database what was previously filled in. Also to note, in the production environment i don't seem to have this problem. END UPDATE] For examp...

What is unicode character 2028 (LS / Line Separator) used for?

I was thinking to myself that the line breaking problem must be somewhat solved by someone, but maybe not widely adopted. Being forward thinking, I went to search to see if there was a platform independent unicode method to separate lines. In my search I found unicode character 2028. Then, I found Jeff Atwoods post on this topic where he...

Adding text in a new line in WPF RichTextBox at runtime

I want to add some text in a WPF RichTextBox at runtime in a new line. I can do this using: FlowDocument mcFlowDoc = new FlowDocument(); mcFlowDoc = richTextBox.Document; Paragraph pr = new Paragraph(); pr.Inlines.Add(status); mcFlowDoc.Blocks.Add(pr); StatusText.Document = mcFlowDoc; But there is too much of a gap between two lines. ...