Convert string to a string array
-
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
-
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
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). -
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).Thanks Robert!
-
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
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]);