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 8667105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:53:22+00:00 2026-06-12T17:53:22+00:00

On running below program error is shown ** Unhandled Exception : systemArgumentOutofRange:Index and length

  • 0

On running below program error is shown
**

Unhandled Exception : systemArgumentOutofRange:Index and length must
refere to location within string.

**

string input = "OneTwoThree sdfhguiosdrb asdhfuiaserthf aseiryaseuigraweui";           

int size = input.Length;
if (input.Length > 30)
{
    msg1 = input.Substring(0, 30);
    msg2 = input.Substring(msg1.Length, size);
    Console.WriteLine("Message: {0}", msg1);
    Console.WriteLine("\nMessage: {0}", msg2);
}
else
    Console.WriteLine(input);

Please help what I am doing wrong.

  • 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-06-12T17:53:23+00:00Added an answer on June 12, 2026 at 5:53 pm

    you are doing wrong on this line

    msg2 = input.Substring(msg1.Length, size);
    

    what you are doing here is, creating a substring msg2 that is longer then the size of your first string msg1,

    here, your msg1.Length equals 30 and your size equals 58 means that you are trying to create a string having startingIndex = 30 and Length = 58 and this will be impossible in this condition, because the Length of your second string msg1 is 30 and it is less then Size i.e. 58.

    Albin Sunnanbo answer is good as per your requirement.i.e.

    msg2 = input.Substring(msg1.Length, size - msg1.Length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting he following Exception while running my Quartz Schdular program. Below is
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
While running unit tests, I'm getting the MDA shown below. In the error message,
I can't launch my program on Android, get the error shown below: eclipse version,
I receive the error below when running the following function. The catch says the
I get the following error when running the code below: invalid byte sequence in
I am getting an argument of length zero after running the code below. I
while running: rake snorby:setup getting below error: rake aborted! You have already activated rake
I am getting below error when running a target of ANT script. Error message
I get the following error when running a drawing program I am working on

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.