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

记录。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM