Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a string which is "ABCD1234", if I use substring to cut the string as below:

C#
string strOld = "ABCD1234"
string strNew = strOld.Substring(4, 7);


Would the output be "1234" even I do not value anymore after the value "4"?
I can't debug it at my PC as my PC has gone for repair shop. Any help would be appreciated.
Posted
Comments
PIEBALDconsult 2-Jul-15 0:14am    
" ArgumentOutOfRangeException
startIndex plus length indicates a position not within this instance.
" -- https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx
Jamie888 2-Jul-15 1:59am    
Yes sir. Thank you for your response. It clears my clouds now. Thank you.

1 solution

Nope. I tried running the code through here http://www.tutorialspoint.com/compile_csharp_online.php[^]

I've changed the number 7 to 4 to output 1234.

C#
using System.IO;
using System;

class Program
{
    static void Main()
    {
        string strOld = "ABCD1234";
        string strNew = strOld.Substring(4, 4);
        Console.WriteLine(strNew);
    }
}
 
Share this answer
 
Comments
Jamie888 2-Jul-15 1:59am    
Yes sir. Thank you for your effort.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900