C + + substr () and Java substring () differences

Source: Internet
Author: User

Java and C + + are all about substrings, C + + is substr (), Java is substring (), the use of the two is slightly different, first for the case of only one parameter:

Both S.substr (start) and s.substring (start) represent substrings starting at the start position to the end of the string

For cases with two parameters, there is a difference between the two

C + +: substr (start, Len), the starting position of the first argument, and the second argument is the length of a substring

Java:substring (start, end), the first argument is the start position, the second argument is the end position

You can refer to the following example code:

C++:

string " HelloWorld "  << s.substr (44//  oworcout << s.substr (4//  Oworld

Java:

String s = "HelloWorld"; System.out.println (s.substring (//  owor//  Oworld

C + + substr () and Java substring () differences

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.