I want create function in c# WPF that returns 10 digit values. It contains as below

  1. One Digit (Static) -> 'G'
  2. Two Digit (Dynamic) -> '19' Of current Year
  3. Two Digit (Dynamic) -> '04' of Current Month
  4. Five Digit (Dynamic) -> '00284' <- It is returned from sql table. The length of this must be fixed.

The return value for above code is 'G190400284' (I want this value as return) if my five digit(4.) value is supposed to 1 then it's returns 'G1904000001'

1 Answers

0
gsharp On Best Solutions

Something like that?

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine(CreateString(1));
        Console.WriteLine(CreateString(284));
    }


    public static string CreateString(int id)
    {
        var n = DateTime.Now;
        return "G" + n.Year.ToString().Substring(2,2) + n.Month.ToString().PadLeft(2,'0') + id.ToString().PadLeft(5,'0');
    }

}

// This returns
// G190400001
// G190400284

https://dotnetfiddle.net/oteEpe