newline

JS regex to split by line

你离开我真会死。 提交于 2019-12-28 11:40:11
问题 How do you split a long piece of text into separate lines? Why does this return line1 twice? /^(.*?)$/mg.exec('line1\r\nline2\r\n'); ["line1", "line1"] I turned on the multi-line modifier to make ^ and $ match beginning and end of lines. I also turned on the global modifier to capture all lines. I wish to use a regex split and not String.split because I'll be dealing with both Linux \n and Windows \r\n line endings. 回答1: arrayOfLines = lineString.match(/[^\r\n]+/g); As Tim said, it is both

Newline removal not working after trying to verify it exists

依然范特西╮ 提交于 2019-12-28 07:04:08
问题 I am making a code to parse some input data and write it to a file in a special formatting. I am removing a newline from each string token as so: token[strlen(token)-2] ='\0' It is -2 because the last element is \0 . This much works. However, the final element of the input data does NOT have a newline, so using just that ends up removing the second-to-last character from the last input set. original input: 0.38 after running it through the removal: 0.3 The obvious solution is to check if the

write newline into a file

為{幸葍}努か 提交于 2019-12-28 05:29:04
问题 considering the following function private static void GetText(String nodeValue) throws IOException { if(!file3.exists()) { file3.createNewFile(); } FileOutputStream fop=new FileOutputStream(file3,true); if(nodeValue!=null) fop.write(nodeValue.getBytes()); fop.flush(); fop.close(); } what to add to make it to write each time in the next line? for example i want each words of a given string in a seperate lline for example: i am mostafa writes as: i am mostafa 回答1: To write text (rather than

jQuery textarea append newline behavior

拥有回忆 提交于 2019-12-28 02:49:06
问题 I'm trying to append a strings which end in newlines to a textarea using jQuery. However, different newline tokens show different behavior in Firefox3.5 and IE8, and I can't seem to find a way to use something that works for both browsers. \n works in FF but not in IE <br/> and \r\n work in IE but not in FF No luck using <pre></pre> tags either I've seen info on the IE innerHTML issue but I'm not exactly sure how to best approach this problem in jQuery. Thanks for any help! 回答1: Not sure how

Set-Content appends a newline (line break, CRLF) at the end of my file

徘徊边缘 提交于 2019-12-28 02:08:09
问题 My original config file (web1.config) has no extra line and when viewed in notepad (showing all characters) looks as: <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.6" /> <httpRuntime targetFramework="4.6" /> </system.web> <appSettings> <add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" /> </appSettings> </configuration> Now, I need to apply the script to change my database name to something else

How to split a string by new lines in Swift

╄→гoц情女王★ 提交于 2019-12-28 02:04:08
问题 I have a string that I got from a text file. Text file: Line 1 Line 2 Line 3 ... I want to convert it to an array, one array element per line. [ "Line 1", "Line 2", "Line 3", ... ] Depending on how the file was saved, the string could take one of the following forms: string = "Line 1\nLine 2\nLine 3\n..." where \n is the new line (line feed) character string = "Line 1\r\nLine 2\r\nLine 3\r\n..." where \r is the carriage return character. As I understand it, \n is commonly used in Apple/Linux

How to split a string by new lines in Swift

夙愿已清 提交于 2019-12-28 02:04:08
问题 I have a string that I got from a text file. Text file: Line 1 Line 2 Line 3 ... I want to convert it to an array, one array element per line. [ "Line 1", "Line 2", "Line 3", ... ] Depending on how the file was saved, the string could take one of the following forms: string = "Line 1\nLine 2\nLine 3\n..." where \n is the new line (line feed) character string = "Line 1\r\nLine 2\r\nLine 3\r\n..." where \r is the carriage return character. As I understand it, \n is commonly used in Apple/Linux

How to replace different newline styles in PHP the smartest way?

淺唱寂寞╮ 提交于 2019-12-27 11:40:10
问题 I have a text which might have different newline styles. I want to replace all newlines '\r\n', '\n','\r' with the same newline (in this case \r\n ). What's the fastest way to do this? My current solution looks like this which is way sucky: $sNicetext = str_replace("\r\n",'%%%%somthing%%%%', $sNicetext); $sNicetext = str_replace(array("\r","\n"),array("\r\n","\r\n"), $sNicetext); $sNicetext = str_replace('%%%%somthing%%%%',"\r\n", $sNicetext); Problem is that you can't do this with one

Match newlines in non empty lines and not preceded by some characters

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 17:08:19
问题 I tried to use the regexp (?<=^(?![ \t]*@).+)(?<![\{\};:)]|//.{0,1024}|^[ \t]+)\R to: Match newlines without matching preceding characters Don't match newlines in only-space lines (empty lines) Don't match newlines in lines started by optional spaces (not newlines) and at-symbol '@'. Don't match newlines in lines containing [unescaped] '//'. Don't match newlines preceded by '{', '}', ';' or ':'. (better if doesn't match newlines preceded by optional spaces and that characters.) That regexp

removing space before new line in java

一个人想着一个人 提交于 2019-12-25 10:05:54
问题 i have a space before a new line in a string and cant remove it (in java). I have tried the following but nothing works: strToFix = strToFix.trim(); strToFix = strToFix.replace(" \n", ""); strToFix = strToFix.replaceAll("\\s\\n", ""); 回答1: myString.replaceAll("[ \t]+(\r\n?|\n)", "$1"); replaceAll takes a regular expression as an argument. The [ \t] matches one or more spaces or tabs. The (\r\n?|\n) matches a newline and puts the result in $1 . 回答2: try this: strToFix = strToFix.replaceAll(" \