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