[英]Want text to start on a new line
如果您要照顾好自己,那么我就在做一个主机游戏,这样您就不会吃得过多或吃饱了。 我遇到一个问题,即文本不在新行开头。 我该如何解决?
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your name, please: ");
string name = Console.ReadLine();
Console.WriteLine("Good choice, " + name);
Console.Write("Press F to feed yourself(+10) and D to drink some water(+10)");
int hunger = 60;
int thirst = 60;
while (hunger < 101)
while (hunger > 1)
while (thirst < 101)
while (thirst > 1)
{
System.Threading.Thread.Sleep(5000);
Console.Write(" ");
{
hunger = hunger - 2;
thirst = thirst - 4;
Console.Write("Food: {0:0.0}".PadRight(15), hunger);
Console.Write("Water: {0:0.0}".PadRight(70), thirst);
}
}
if (hunger < 101)
{
Console.Write("You died from over feeding, RIP:" + name);
System.Threading.Thread.Sleep(3000);
{
System.Environment.Exit(1);
}
}
}
}
}
当文本告诉用户当前的食物和水时,我希望文本从新的一行开始。 我该怎么做呢?
您应该使用Console.WriteLine
而不是Console.Write
如果您要拆分的字符串为“ complexe”,则在需要退格的位置插入“ \\ n”
编辑 :“ \\ n”特定于Windows平台。 如注释中所述,如果您是多平台驱动的,则可以使用Environment.NewLine
。
"\r\n" - windows
用于创建新行。
string newline = System.Environment.NewLine;
您可以尝试以下两种选择:
1)String.Replace(“ Any Keyword”,Environment.NewLine);
2)在字符串中使用“ \\ n”。
谢谢
吉滕德拉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.