C # How to Implement left and right truncation strings in winform

Source: Internet
Author: User

C # How to Implement left and right truncation strings in winform

The substring method provided in C # can implement related functions.

First, let's review the substring method.

Usage 1: String. substring method (startindex, length)

Returns the child string of length starting with startindex in this string.

Startindex: Index of the starting position of the substring, starting from 0.

Length: the number of truncated characters in the substring.

Usage 2: String. substring method (startindex)

Returns all the remaining characters starting from startindex in the string.

Startindex: Index of the starting position of the substring, starting from 0.

After getting familiar with this method, we will implement how to extract strings left and right.

Left truncation: Str. substring (0, I) returns, and returns the I characters on the left.

Right truncation: Str. substring (Str. Length-I, I) returns, and returns the I characters on the right.

See the following example:

Int I = 2;

String STR = "123456 ″;

String strleft = Str. substring (0, I );

String strright = Str. substring (Str. Length-I, I );

Strleft is "12 ″

Strright is "56 ″

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.