CString string Lookup and interception

Source: Internet
Author: User
Tags assert function examples

This article summarizes CString left (), Mid (), right () and several CString string lookup related functions to use, first need to find, CString has the following several lookup functions, respectively, find (), Reversefind (), Findoneof ().

One, CString find (), findoneof (), Reversefind ()

All three functions return a value of integer int. 1, find ()

This function starts at the left 0 index, finds the first character position that appears, and returns position. Examples are as follows:

1 CString s ("ABCD");
2 ASSERT (S.find (' b ') = = 1);

Return value: If found, returns 1 2, findoneof () , where the start of the 0 index is not found.

Given a string, and then find the first character position that appears, the following example:

1 CString s ("abcdef");
2 ASSERT (s.findoneof ("ZB") = = 1);

Return value: If found, returns 1 3, Reversefind () , where the start of the 0 index is not found.

The function reverses the position where the character appears. Examples are as follows:

1 CString s ("ABCD");
2 ASSERT (S.reversefind (' b ') = = 2);

Return value: If found, returns the location starting at 0 not found, returns-1 two, CString left (), Mid (), right ()

After the lookup is complete, we may need to intercept the string. The CString has several string intercept functions as follows. 1, left (int ncount)

The function intercepts the left ncount character, and if a double-byte character is encountered (as is also understood by mid and right below), such as Chinese, the garbled text may be truncated. Because the ncount is counted by byte. 2, Mid (int nfirst) and mid (int nfirst, int ncount)

The Mid (int nfirst) function intercepts the string that starts at Nfirst until the end of the string.

The Mid (int nfirst, int ncount) function intercepts the ncount byte characters from the beginning of the Nfirst. 3, right (int ncount)

This function intercepts the right ncount byte character.

The left (), Mid (), right () function examples are as follows:

1

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.