C# 控制台 字符串 左右 移动

来源:互联网 发布:淘宝 云客服 工资 编辑:程序博客网 时间:2024/04/30 08:15

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一行字符串");
            String s = Console.ReadLine();
            StringBuilder r = new StringBuilder(s);
            int width = Console.WindowWidth;
            for (int i = 0; i < width-s.Length; i++)
            {
                Console.Write(r.Insert(i, " "));
                System.Threading.Thread.Sleep(100);
                Console.Clear();
            }
            for (int i = width-s.Length-1; i >= 0; i--)
            {
                Console.Write(r.Remove(i, 1));
                System.Threading.Thread.Sleep(100);
                Console.Clear();
            }
        }
       
    }
}

原创粉丝点击