In my previous tutorials, I’d explained how to show confirm message box using javascript, how to show alert message from code-behind, how to call javascript function from code-behind and other more cracking tutorials on Asp.net, JavaScript, jQuery here.
There are several methods available to split the string. One of them is using jquery split function but here in this tutorial, I’ll explain how to split the string date into array of day, month and year from code-behind in asp.net using C# and Vb.net split() method.
If you want to split string into array, it’s easy to do so. For that you need to use split function in asp.net c# or vb.net. To use this method it will require separator as a parameter like /, @, – etc as per your choice, use to separate given string.
Here is the code to split string date into specific day, month and year.
Split String Date to Array of Day, Month and Year – [C#]
//split string date by separator, here I'm using '/'
string[] arrDate = strDate.Split('/');
//now use array to get specific date object
string day = arrDate[0].ToString();
string month = arrDate[1].ToString();
string year = arrDate[2].ToString();
Split String Date to Array of Day, Month and Year – [Vb.net]
'split string date by separator, here I'm using '/'
Dim arrDate() As String = strDate.Split("/"c)
'now use array to get specific date object
Dim day As String = arrDate(0).ToString()
Dim month As String = arrDate(1).ToString()
Dim year As String = arrDate(2).ToString()
Example Result
day: “26”;
month: “07”;
year: “2011”;
error
{“Index was outside the bounds of the array.”}
please can you help me.