zoukankan      html  css  js  c++  java
  • C#控制台输出退格实现变换闪烁的字符效果

    C#控制台输出退格实现变换闪烁的字符效果,传统的Console.Clear()方法能清除控制台上的所有内容。

    如果用 Console.Write('u0008');可以实现输出退格,这样就可以方便地清除某一个或者某几个字符内容。

    实例如下:

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Threading;

     

    namespace ConsoleApplication2

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Write("Number : ");

                for (int i = 0; i < 10000; i++)

                {

                    switch (i)

                    {

                        case 10: FlashingString(i, 1); break;

                        case 100: FlashingString(i, 2); break;

                        case 1000: FlashingString(i, 3); break;

                        case 10000: FlashingString(i, 4); break;

                        default: FlashingString(i); break;

                    }

                    Thread.Sleep(100); //间歇变换

                }

                Console.ReadLine();

            }

     

            //显示变换闪烁的字符方法

            public static void FlashingString(int num, int backlength = 0)

            {

                if (num > 0)

                {

                    if (backlength <= 0) backlength = num.ToString().Length;

                    // 清除旧的字符

                    for (int i = 0; i < backlength; i++)

                    {

                        //输出退格

                        Console.Write('u0008');

                    }

                }

                // 输出新字符

                Console.Write(num);

            }

        }

    }

  • 相关阅读:
    解决ValueError: Some of types cannot be determined by the first 100 rows,
    关于number_format的一个报错
    关于IPV6审核被拒问题处理
    项目集成三方库由静态库转为动态库遇到的问题总结
    Swift判断对象属于什么类型
    运行项目报错 报scandir() has been disabled for security reasons
    CocoPods port 443
    Jetpack学习-WorkManager
    Jetpack学习-Paging
    Jetpack学习-Navigation
  • 原文地址:https://www.cnblogs.com/a-du/p/9020189.html
Copyright © 2011-2022 走看看