c# - 经常打印“-”字符有多长
问题描述
我在我自己的小程序中工作,所以我想问我如何才能进行变量测试以给出 - 这么长的 intro.Length 是多少。
所以字符串介绍是 66 个字符,空间长现在我希望它只打印 - 66 次,如 ----------------------------- ----------------- 但是 66 个字符长我该怎么做?
using System;
namespace ConsoleApp1
{
class Program
{
public static int alter;
public static string vorname;
public static string nachname;
public static string jeah;
public static string intro;
public static int abc;
public static string test;
static void Main(string[] args)
{
intro = "Hey you wanna try my small Program? If Yes enter Y if not enter N!";
abc = intro.Length;
test = "-" * ;
Console.Write(test);
jeah = Console.ReadLine();
if (jeah == "Y")
{
Vorname();
Nachname();
Alter();
Output();
} else
{
Console.WriteLine("Schade dann nicht!");
}
Console.ReadKey();
}
解决方案
As simple as using the string's constructor like this :
string s = new string('-', 66);
推荐阅读
- python - 为什么这个 dict.get() 会抛出这个错误?
- sql - SQL 删除表函数
- flutter - 导航到另一个页面时获取图像提供程序脏状态
- r - 不要回显到 R 控制台
- mongodb - 2 pod 具有未绑定的即时 PersistentVolumeClaims - Kubernetes
- python - 在 matplotlib 中创建一个没有可映射的颜色条
- azure - 出站 Internet 访问受限时如何在 VM 上运行 Azure Powershell cmdlet
- javascript - D3 - 具有正值和负值的图表
- c++ - 可以改善我的字符串拆分功能的建议
- c++ - C++ 函数已经有一个主体