【问题标题】:Overwrite current line in consle (equivalent of python "\r")覆盖控制台中的当前行(相当于 python "\r")
【发布时间】:2015-02-10 18:20:02
【问题描述】:

在 Python 中,我会使用以下 for 来用新文本覆盖当前行:

import sys
sys.stdout.write('\r[Test]: Testing')

但是如何在 C# 中做到这一点我已经尝试过:

Console.WriteLine("\r[This is a test]");
Console.WriteLine("\r[This the next stage]");

但是这段代码写在新行而不是覆盖同一行。

【问题讨论】:

  • 如果您指出您要完成的工作,将会有所帮助。如果您尝试发出新行,则取决于平台。对于 Windows,您必须拥有 \r\n
  • 什么,具体来说,“没用”?
  • @JonathanWood 我认为我们的目标是覆盖之前的字符串,所以 \r\n 使用起来是错误的。
  • @JonathanWood 如果您正在写出一个文件并使用只知道如何处理该特定换行符的程序读取它。

标签: c# stdout


【解决方案1】:

等效代码为:

Console.Write("\r[Test]: Testing");

Console.WriteLine 将在您的字符串打印后添加一个新行。

【讨论】:

    猜你喜欢
    • 2023-04-11
    • 2016-07-30
    • 2011-07-07
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2012-08-25
    相关资源
    最近更新 更多