Home > Blockchain >  Format string - How to edit to format HH:mm:ss
Format string - How to edit to format HH:mm:ss

Time:03-07

string test = "121410"

I want transform this string in string too but with value:

test="12:14:10"

How can i make this?

CodePudding user response:

You should easily be able to pop the : entries in, and remove them again to reverse the function

using System;
                    
public class Program
{
    public static void Main()
    {
        string test = "121410";
        
        // original value
        Console.WriteLine(test);
        
        string testFormatted = test.Substring(0, 2)   ":"   test.Substring(2, 2)   ":"   test.Substring(4, 2);
            
        // value in time display format
        Console.WriteLine(testFormatted);
        
        string testUnformatted = testFormatted.Replace(":", String.Empty);
        
        // original value restored from time display format
        Console.WriteLine(testUnformatted);
    }
}

Output

121410
12:14:10
121410
  •  Tags:  
  • c#
  • Related