作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们都知道如何使用\t 进一步打印字符串
printf ("Hello\tthere!\n");
输出:
Hello there!
向后打印一个选项卡怎么样?我知道我们可以使用\r 从行的开头开始,但是在某些情况下缩进比这更复杂,我正在寻找类似\bt (如果存在)这样的东西,这样我可以写:
printf ("Hello\tthere! \n\tHow\n\btare you?\n");
获取输出:
Hello there!
How
are you?
编辑
我对这里回复的数量和速度感到惊讶,有时甚至对一些评论的无用性感到惊讶,但只有少数。我想要实现的目标当然比这更复杂,它正确地格式化 XML 文件以使其易于阅读。我想确定没有更简单的方法,回复确认没有,谢谢。
编辑2
抱歉,大家否决这个问题是正确的,首先是因为我没有指定我正在写入文本文件,其次是因为我假设选项卡可以被文件处理程序“记住”。抱歉浪费您的时间。
最佳答案
使用printf,您可以显式控制进行制表操作的次数。要返回选项卡,您只需使用更少的选项卡即可。从您提供的示例来看,您似乎希望记住选项卡级别,并且如何缩进比打印时实际缩进的距离更远。它会出现在与那里!和是你吗?
相同的制表位处假设:
printf ("Hello\tthere! \n\tHow\n\btare you?\n");
您期望看到:
Hello there! Howare you?
Then just don't add the tab before are you? and you will get what you want. To get fewer tabs, just add fewer \t symbols to your printf. printf doesn't have any memory of what tabbing has occurred before.
printf ("Hello\tthere! \n\tHow\nare you?\n");
关于c - Perl(或C printf)后退一个选项卡,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936875/
我是一名优秀的程序员,十分优秀!