硬包和软包的区别?
我正在编写一个文本编辑器。 在查看其他文本编辑器后,我注意到其中许多都指的是“软”换行与“硬”换行。 有什么不同? 我似乎无法通过搜索找到答案。
I am in the process of writing a text editor. After looking at other text editors I have noticed that a number of them refer to a "soft" versus "hard" wrap. What is the difference? I can't seem to find the answer by searching.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
硬换行会在文本中的换行点插入实际换行符,而软换行则实际文本仍位于同一行,但看起来像是分为几行。
A hard wrap inserts actual line breaks in the text at wrap points, with soft wrapping the actual text is still on the same line but looks like it's divided into several lines.
文本编辑器通常会自动将文本自动换行成带有硬换行符的段落,但如果您稍后返回并编辑/添加/删除单词,则文本重新排列成漂亮的段落的情况不太常见。 (您可以在 emacs 中使用 Mq 手动执行此操作。)
这相当烦人,因为像我这样的强迫症患者随后必须返回并在适当的点手动重新插入硬中断。
另一方面,软包装很烦人,因为大多数命令行工具都使用基于行的差异(版本控制是我最注意到的地方)。 如果您有一个 1/3 页的段落经过软包装并修复了拼写错误,则基本上不可能在常规
diff
输出或类似输出中看到更改的位置。It's usual for text editors to auto-wrap text into paragraphs with hard newlines, but it's less common for the text to be re-flowed into a nice paragraph if you come back later and edit/add/remove words later on. (You can do this manually in emacs with M-q.)
This is rather annoying, since obsessive compulsive people like me then go back and have to manually re-insert the hard breaks at the appropriate points.
On the other hand, soft wrapping is annoying because most all command line tools use line-based diff-ing (version control is where this becomes most noticeable to me). If you've got a 1/3-page paragraph that's soft wrapped and fix a typo, it's basically impossible to see where the change is in a regular
diff
output or similar.soft :以表单形式提交时,文本区域中的文本不会换行。 这是默认的
hard :在表单中提交时,文本区域中的文本会换行(包含换行符)。 使用“hard”时,必须指定 cols 属性
参考:W3Schools
soft : The text in the textarea is not wrapped when submitted in a form. This is default
hard : The text in the textarea is wrapped (contains newlines) when submitted in a form. When "hard" is used, the cols attribute must be specified
Reference: W3Schools