line-breaks

Neatest way to remove linebreaks in Perl

杀马特。学长 韩版系。学妹 提交于 2019-12-18 10:16:45
问题 I'm maintaining a script that can get its input from various sources, and works on it per line. Depending on the actual source used, linebreaks might be Unix-style, Windows-style or even, for some aggregated input, mixed(!). When reading from a file it goes something like this: @lines = <IN>; process(\@lines); ... sub process { @lines = shift; foreach my $line (@{$lines}) { chomp $line; #Handle line by line } } So, what I need to do is replace the chomp with something that removes either Unix

Writing TXT File with PHP, Want to Add an Actual Line Break

江枫思渺然 提交于 2019-12-18 03:59:18
问题 I am writing a TXT file using PHP. I want to insert actual line breaks into the TXT file wherever necessary. I have tried all combinations of \n \r \r\n \n\r ... but these are not causing any linebreaks to appear - in most cases, I am seeing the text "\n" appear in the TXT file, with no linebreak. I have also tried chr(13). Any other ideas would be appreciated. 回答1: Sounds to me like you might be using single quotes, i.e. '\n' rather than "\n" . If you wanted to continue with a single quotes

How do i remove all linebreaks?

断了今生、忘了曾经 提交于 2019-12-18 03:15:06
问题 I have something like this: <node TEXT=" txt A "/> <node TEXT=" txt X "/> <node> <html> <p> txt Y </p> </html> </node> <node TEXT="txt B"/> and i want to use XSLT to get this: txt A txt X txt Y txt B I want to strip all useless whitespaces and linebreaks of @TEXT's and CDATA's. The only XML-input that is giving structure to the output are the <node> -tags. 回答1: The following transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method=

display line breaks asp.net mvc razor

坚强是说给别人听的谎言 提交于 2019-12-17 23:34:17
问题 I'm using the following to make the text output the line breaks entered in a <textarea> HTML element. MvcHtmlString.Create(Model.Post.Description.Replace(Environment.NewLine, "<br />")) Is there a nicer way to do this? 回答1: Your code is vulnerable to XSS attacks as it doesn't HTML encode the text. I would recommend you the following: var result = string.Join( "<br/>", Model.Post.Description .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(x => HttpUtility.HtmlEncode(x))

use xsl to output plain text

纵饮孤独 提交于 2019-12-17 22:21:09
问题 I needed to use XSL to generate simple plain text output from XML. Since I didn't find any good, concise example online, I decided to post my solution here. Any links referring to a better example would of course be appreciated: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" > <xsl:output method="text" omit-xml-declaration="yes" indent="no"/> <xsl:template match="/"> <xsl:for

Finding line break and carriage return (\r\n) in MySQL

时光毁灭记忆、已成空白 提交于 2019-12-17 18:37:06
问题 I can't seem to find any info about this on the internet (or I'm just not looking in the right direction). I have a few fields in my MySQL database containing a carriage return and line break \r\n . Is there somebody who can tell me how to find them by using a query?? 回答1: SELECT * FROM mytable WHERE mycolumn REGEXP "\r\n"; finds all records in mytable where mycolumn contains a \r\n sequence. 来源: https://stackoverflow.com/questions/10997159/finding-line-break-and-carriage-return-r-n-in-mysql

Why doesn't $ in .NET multiline regular expressions match CRLF?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 17:43:15
问题 I have noticed the following: var b1 = Regex.IsMatch("Line1\nLine2", "Line1$", RegexOptions.Multiline); // true var b2 = Regex.IsMatch("Line1\r\nLine2", "Line1$", RegexOptions.Multiline); // false I'm confused. The documentation of RegexOptions says: Multiline : Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string. Since C# and VB.NET are mainly used in the Windows world, I

Removing redundant line breaks with regular expressions

痞子三分冷 提交于 2019-12-17 16:44:17
问题 I'm developing a single serving site in PHP that simply displays messages that are posted by visitors (ideally surrounding the topic of the website). Anyone can post up to three messages an hour. Since the website will only be one page, I'd like to control the vertical length of each message. However, I do want to at least partially preserve line breaks in the original message. A compromise would be to allow for two line breaks, but if there are more than two, then replace them with a total

Carriage Return/Line Feed in .Net Resource File (App_GlobalResources)

泄露秘密 提交于 2019-12-17 15:42:46
问题 I'm keeping several texts in an App_GlobalResources.resx file. The texts have to be multi-line and I need to have them contain line feeds. However, when I read the contents, all line feeds are gone ( \r\n is printed, not as CRLF 10 13 control character). I know that I could work around this by re-replacing \r\n (or anything else for that matter) back to CRLF when I read the contents, but I wondered why these clearly text-targeted resx files ignore control characters - and CRLF is kind of

Carriage Return/Line Feed in .Net Resource File (App_GlobalResources)

风流意气都作罢 提交于 2019-12-17 15:42:00
问题 I'm keeping several texts in an App_GlobalResources.resx file. The texts have to be multi-line and I need to have them contain line feeds. However, when I read the contents, all line feeds are gone ( \r\n is printed, not as CRLF 10 13 control character). I know that I could work around this by re-replacing \r\n (or anything else for that matter) back to CRLF when I read the contents, but I wondered why these clearly text-targeted resx files ignore control characters - and CRLF is kind of