I need help to format all the input values to the format ‘##-##/##'. My input might include whole number, fraction or mixed fraction...Sample input 3, 1/1, 1 1/2. I have tried the below code it is giving expected result. Can someone please help for a standard and concise way of doing this
using System.IO;
using System;
using System.Linq;
class Program
{
static void Main()
{
var input1 = "3"; /*Expected result 03-00/00 */
var input2 = "1/1"; /*Expected result 00-01/01*/
var input3 = "1 3/4"; /*Expected result 01-03/04*/
string[] splittedValue1= input1.Split( '/', ' ' );
string[] splittedValue2= input2.Split( '/', ' ' );
string[] splittedValue3= input3.Split( '/', ' ' );
/*Expected result 03-00/00 */
if(splittedValue1.Count()==1)
{
String test =splittedValue1[0].PadLeft(2, '0') +"-00/00" ;
Console.WriteLine(test);
}
/*Expected result 00-01/01*/
if(splittedValue2.Count()==2)
{
String format="00-00";
String test =Convert.ToInt32(splittedValue2[0]).ToString(format) + "/" + splittedValue2[1].PadLeft(2, '0');
Console.WriteLine(test);
}
/*Expected result 01-03/04*/
if(splittedValue3.Count()==3)
{
String test =splittedValue3[0].PadLeft(2, '0') +"-" +splittedValue3[1].PadLeft(2, '0') + "/" + splittedValue3[2].PadLeft(2, '0');
Console.WriteLine(test);
}
}
}