How to split string in group in vb.net

Posted by amol kadam on Stack Overflow See other posts from Stack Overflow or by amol kadam
Published on 2010-04-09T04:58:18Z Indexed on 2010/04/09 5:03 UTC
Read the original article Hit count: 489

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about substring