Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert string to a string array

Convert string to a string array

Scheduled Pinned Locked Moved C#
data-structurestutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, I was wondering how to convert a string like: string myString = "1:00 PM,2:00 PM,8:00 PM,9:00 PM"; into a string array (or even better a DateTime array). thanks, Ron

    R T 2 Replies Last reply
    0
    • M myNameIsRon

      Hi, I was wondering how to convert a string like: string myString = "1:00 PM,2:00 PM,8:00 PM,9:00 PM"; into a string array (or even better a DateTime array). thanks, Ron

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      string[] splitted = myString.Split(',');

      To convert the result to a DateTime array you will have to loop through it and make it manually (Convert.ToDateTime on each element).

      M 1 Reply Last reply
      0
      • R Robert Rohde

        string[] splitted = myString.Split(',');

        To convert the result to a DateTime array you will have to loop through it and make it manually (Convert.ToDateTime on each element).

        M Offline
        M Offline
        myNameIsRon
        wrote on last edited by
        #3

        Thanks Robert!

        1 Reply Last reply
        0
        • M myNameIsRon

          Hi, I was wondering how to convert a string like: string myString = "1:00 PM,2:00 PM,8:00 PM,9:00 PM"; into a string array (or even better a DateTime array). thanks, Ron

          T Offline
          T Offline
          techieboi
          wrote on last edited by
          #4

          Hope this helps... string myString = "1:00 PM,2:00 PM,8:00 PM,9:00 PM"; string[] myStringArray; DateTime[] myDateArray; // Split myString into an array myStringArray = myString.Split(new char[] { ',' }); // Create an array to hold our times myDateArray = new DateTime[myStringArray.Length]; // Step through our string array and create the times for (int index = 0; index < myStringArray.Length; index ++) myDateArray[index] = DateTime.Parse(myStringArray[index]);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups