Search code examples
c#string.net-micro-framework

How can I add a SPACE halfway through a string value?


I'm trying to create a STRING in JSON format. However, one of the fields (from my editing/removing ALL spaces) now leaves a line like "START":"13/08/1410:30:00". However, I want to add a space between the date and time? I have tried using the ToCharArray() method to split the string, but I am at a loss as to how to add a space between the DATE and TIME part of the string?

For Example, i am trying to get: "START":"13/08/14 10:30:00" but instead am getting

"START":"13/08/1410:30:00"

Please note. The length of the string before the space requirement will always be 17 characters long. I am using VS 2010 for NETMF (Fez Panda II)


Solution

  • If the split position is always 17, then simply:

    string t = s.Substring(0, 17) + " " + s.Substring(17);