//去除首位 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; }
static void Main(string[] args) { try //控制用戶輸入字符串 { //提示輸入 Console.WriteLine("輸入要轉換的值"); //接收控制台輸入的值 string Input = Convert.ToString(Console.ReadLine()); Console.WriteLine(RemoveFirstPlace(Input)); } catch { Console.WriteLine("需要輸入字符串"); } Console.ReadKey(); }
記錄。
