C# 數字轉字串補0 & 字串補0

C# 數字轉字串補0 & 字串補0

C# 數字轉字串補0 & 字串補0



01.數字轉字串補0:

this.f1_textBox2.Text = String.Format("{0:0000000000000000}",(Convert.ToInt16(this.f1_textBox2.Text) + 1));


 

02.字串補0:

string str = "9";
str.PadLeft(4, '0');//-->0009
str.PadRight(4, '0');//-->9000


 

One thought on “C# 數字轉字串補0 & 字串補0

  1. C# 字串(子字串/字串切割/分割/切斷/切段/分段)
    數字轉字串 字串補0 範例


    using System;

    public class Program
    {
    public static void Main()
    {
    string Period="11404";
    Console.WriteLine($"{Period.Substring(0,3)}年{Period.Substring(3,2)}-{(Int32.Parse(Period.Substring(3,2))+1).ToString().PadLeft(2, '0')}月");
    }
    }

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *