Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 711523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:44:41+00:00 2026-05-14T04:44:41+00:00

i’m amol kadam,I want to know how to split string in two part.My string

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:44:41+00:00Added an answer on May 14, 2026 at 4:44 am

    The simplest way (assumming that you can ensure the format) is to use a split:

    dim strTime as string = objDs.Tables(0).Rows(0).("TimeOfAccident")
    dim timeParts() as string =  split(strTime,":")
    dim strTimeHr as string = timeParts(0)
    dim strTimeMn  as string = timePartS(1)
    

    you’ll also want some error handling to check for formatting and that the split generates the array with at least two elements and what not.

    EDIT: After looking more closely at your code, I see the cause of your error.

    You have this code:

    lastIndex = strTime.Length 
    strTimeHr = strTime.Substring(0, index)
    strTimeMin = strTime.Substring(index + 1, lastIndex)
    

    With that last line giving the error.

    The reason that you’re getting that error is that strings (and other arrays) in VB.Net are ZERO BASED. Which is why in the strTimeHr field, you’re starting at position 0. Length gives you the count, which since the array is zero-based, means the count will be one more than available indexes.

    I.e. the last element in a zero based array is the length of the array minus 1.

    Therefore, changing your original code to this:

    lastIndex = strTime.Length  - 1
    strTimeHr = strTime.Substring(0, index)
    strTimeMin = strTime.Substring(index + 1, lastIndex)
    

    will work as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.