C # And Substring () in Java (),

Source: Internet
Author: User

C # And Substring () in Java (),

Vomit... Be sure not to clean up the computer with cleanup software. Otherwise you will be hurt!
Substring () in C ()

Example

Implementation Code

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;

Namespace WindowsDemo
{
Class Program
{
Static void Main (string [] args)
{
// Call external functions
SubStringDemo ();
}
// Obtain the sub-string Function
Static void subStringDemo ()
{
String str = "123456 ";
String subStr1 = str. Substring (5 );
String subStr2 = str. Substring (0, 5 );
Console. WriteLine ("single parameter:" + subStr1 );
Console. WriteLine ("two parameters:" + subStr2 );
Console. ReadKey ();
}
}
}

Through the example, we can conclude that the input parameters of Substring () are different, and the execution functions are also different.

  • When A parameter is passed in, for example, Substring (A) indicates to intercept from the specified index number A of the original string until the last one of the original string;
  • When two parameters are passed in, for example, Substring (A, B) indicates that the obtained string length is B starting from the character whose original string index number is;

Note:

If the input parameter is invalid, an ArgumentsOutOfRangeException error is thrown.

 

 

Substring () in Java ()

Example

Implementation Code

String str = "123456 ";

SubStr = str. Substring (2, 5 );

System. Output. println (subStr );

 

// Output result

345

 

From the preceding example, we can conclude that:

Str. Substring (A, B) indicates the character from string A to string B, which must contain A, which does not contain B, that is, [A, B ).

Note:

If the parameter is invalid, the IndexOutOfBoundsException error is thrown.

 

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.