C# 字符串处理—— 去除首位保留其他

        //去除首位
        public static string RemoveFirstPlace(string s)
        {
            if (s.Length > 1)  //输入空值直接Return
            {
                if (s.StartsWith("0"))  //判断开头是否是零
                    s = s.Substring(1, s.Length - 1); //截取1位
            }
            return s;
        }
View Code
        static void Main(string[] args)
        {
            try //控制用户输入字符串
            {
                //提示输入
                Console.WriteLine("输入要转换的值");
                //接收控制台输入的值
                string Input = Convert.ToString(Console.ReadLine());

                Console.WriteLine(RemoveFirstPlace(Input));
            }
            catch
            {
                Console.WriteLine("需要输入字符串");
            }
            Console.ReadKey();
        }
View Code

记录。

原文地址:https://www.cnblogs.com/qixiaolan/p/9890565.html