How to split string in group in vb.net
- by amol kadam
Hi. i'm amol kadam,I want to know how to split string in two part.My string is in Time format (12:12).& I want to seperate this in hour & minute format.the datatype for all variables are string. for hour variable used strTimeHr & for minute strTimeMin .I tried below code but their was a exception "Index and length must refer to a location within the string.
Parameter name: length"
If Not (objDS.Tables(0).Rows(0)("TimeOfAccident") Is Nothing Or objDS.Tables(0).Rows(0)("TimeOfAccident") Is System.DBNull.Value) Then
strTime = objDS.Tables(0).Rows(0)("TimeOfAccident") 'strTime taking value 12:12
index = strTime.IndexOf(":") 'index taking value 2
lastIndex = strTime.Length 'Lastindex taking value 5
strTimeHr = strTime.Substring(0, index) 'strTime taking value 12 correctly
strTimeMin = strTime.Substring(index + 1, lastIndex) 'BUT HERE IS PROBLEM OCCURE strTimeMin Doesn't taking any value
Me.NumUpDwHr.Text = strTimeHr
Me.NumUpDwMin.Text = strTimeMin
End If