Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 875125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:12:57+00:00 2026-05-15T11:12:57+00:00

I want to split my string s1 = 6/28/2010 4:46:36 PM and s2 =

  • 0

I want to split my string s1 = 6/28/2010 4:46:36 PM and s2 = 16:46:36.5013946 .
and concatenate them to new s3 = 20010062816463650. But when I split s2. my regex doesn’t work. I was paused now.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace ConAppTest
{
    class Program
    {

        static void Main(string[] args)
        {
            string s1 = ""; // date
            string s2 = ""; // time
            Console.WriteLine("{0}", DateTime.Now);
            s1 = DateTime.Now.ToString();
            Console.WriteLine("{0}", DateTime.Now.TimeOfDay);
            s2 = DateTime.Now.TimeOfDay.ToString();

            Regex regex1 = new Regex(@" |:|/");    //6/28/2010 2:19:21 PM
            char[] separators1 = { ' ', '/' };
            foreach (string sub1 in regex1.Split(s1))
            {
                Console.WriteLine("Word1: {0}", sub1);
            }

            Regex regex2 = new Regex(@":|.");  //14:19:21.8771215
            char[] separators2 = { ':', '.' };
            foreach (string sub2 in regex2.Split(s2))
            {
                Console.WriteLine("Word2: {0}", sub2);
            }
        }



    }
}
//output
//6/28/2010 4:46:36 PM
//16:46:36.5013946
//Word1: 6
//Word1: 28
//Word1: 2010
//Word1: 4
//Word1: 46
//Word1: 36
//Word1: PM
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:12:58+00:00Added an answer on May 15, 2026 at 11:12 am

    Why are you using RegEx at all for this?

    Use DateTime.TryParse or DateTime.Parse to parse the input string to a DateTime object (if you need an exact parse, there are also ParseExact and TryParseExact that take a format string).

    You can then use DateTime.ToString with a custom format string that will output the exact output you want directly from DateTime objects.

    DateTime.ToString("yyyyMMddHHmmssff");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to split a string into parts based on a regex (\$\d+\$), but
i want to split a string with regex, then create a dom element where
I have a string in the form MMM/dd/yyyy, ie. May/21/2010. Now I want to
string input = @12.2.2010|7; string pattern = @|; foreach (string result in Regex.Split(input, pattern))
I want to split a string which has content like this: a$b$c but when
I want to split a string using regular expressions but I have run into
I have a string 10/15/2010 I want to split this string into 10, 15,
I want to split a string like first middle last with String.split() . But
I want to split string by setting all non-alphabet as separator. String[] word_list =
I want to split a string like this: abc//def//ghi into a part before and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.