在 Eclipse 中,如何用新行替换字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/156707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Eclipse, how do I replace a character by a new line?
提问by paulgreg
In Eclipse 3.3.2, I would like to replace a character (say ',') by a new line in a file. What should I write in the "Replace with" box in order to do so ?
在 Eclipse 3.3.2 中,我想用文件中的新行替换一个字符(比如“,”)。我应该在“替换为”框中写什么才能这样做?
EDIT : Many answers seems to be for Eclipse 3.4. Is there a solution for Eclipse 3.3.X ?
编辑:许多答案似乎是针对 Eclipse 3.4 的。Eclipse 3.3.X 有解决方案吗?
回答by David Pierre
Check box 'Regular Expressions' and use '\R' in the 'Replace with' box
选中“正则表达式”框并在“替换为”框中使用“\R”
It's a new feature introduced with Eclipse 3.4, See What's New in 3.4
这是与Eclipse 3.4引入的新功能,请参阅新增3.4
回答by emersonblima
Like the others said, just use regular expression, but instead of just \r, put \r\n
就像其他人说的,只使用正则表达式,而不是只是 \r,把 \r\n
回答by Liam
Check box 'Regular Expressions' and use '\n' in the 'Replace with' box
选中“正则表达式”框并在“替换为”框中使用“\n”
回答by loogie
I'm using Helios and it works, however I had some issues with replacement... I wanted to place a line break between any of these brackets "><" (to make each new XML tag go to a new line)... first I had to place a chacter between the 2 brackets, for instance /r, after this i checked the "regular expressions" box and replaced the /r with \R, which resulted in the correct linebreak. otherwise, the replace seemed to be greyed out.
我正在使用 Helios 并且它可以工作,但是我在替换方面遇到了一些问题......我想在任何这些括号 "><" 之间放置一个换行符(以使每个新的 XML 标记转到一个新行)。 . 首先,我必须在 2 个方括号之间放置一个字符,例如 /r,之后我检查了“正则表达式”框并将 /r 替换为 \R,这导致了正确的换行符。否则,替换似乎是灰色的。
回答by paulgreg
I've just found an article about that problem. It seems to be a bug.
我刚刚找到了一篇关于这个问题的文章。这似乎是一个错误。
There's a workaround which is to copy a new line in clipboard and then paste it inside the "replace" box.
有一种解决方法是在剪贴板中复制一个新行,然后将其粘贴到“替换”框中。
回答by user9796835
if the file search is performed with Regular Expressions checkbox checked, then replace all / replace selected will also allow regular expression and will transform \n to a newline in the file(s)
如果在选中“正则表达式”复选框的情况下执行文件搜索,则全部替换/替换选定项也将允许使用正则表达式并将 \n 转换为文件中的换行符