Development journey (4): usage of substring () in C #

Source: Internet
Author: User

First look at the Syntax:

String. substring (INT index, int length)
Index: Start position, starting from 0
Length: the length of the substring you want to obtain

Example:

1 using system; 2 using system. collections. generic; 3 using system. text; 4 5 namespace str_sub 6 {7 class Program 8 {9 static void main (string [] ARGs) 10 {11 string mystring = "Hello word! "; 12 // substring () in C # There are two overloaded functions 13 // The following example 14 string substring1 = mystring respectively. substring (0); 15 // If the input parameter is a long integer and greater than or equal to 0, 16 // the start point is the long integer, 17 // all the remaining strings are taken after the interception. 18 // If the input value is less than // The system will throw an argumentoutofrange exception 20 // indicates that the parameter range is 21 string substring2 = mystring. substring (0, 5); 22 // If two long integer parameters are input, 23 // The first parameter is the starting position of the original string 24 // The last parameter is the length of the substring 25 // The exception 26 27 appears if not met. writeline (substring1); 28 console. writeline (substring2); 29 console. readline (); 30} 31} 32}

 

Program output result:
Hello word!
Hello

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.