The usage of spanincluding and spanexcluding in CString

Source: Internet
Author: User

SpanIncluding simple understanding is to extract a substring contained in a specified string

The note on MSDN says: Look for characters equal to the given string starting with the first character on the left, and if not, return an empty string, and vice versa, continue to find, to the end.

Easy to understand examples

CString str;
CString strdigital ("0123456");
str = "51920";
CString strval = str. SpanIncluding (strdigital);
MessageBox (Strval);

Strval= "51"

Extract the string in str with strdigtal to wait, starting from the first ' 5 ' to find,...., until a character in Str cannot be found in strdigtal ..., in the example, the ' 9 ' condition does not match, return directly to "51"

SpanExcluding and SpanIncluding just the opposite, and find a mismatch with the

CString str;
CString strdigital ("0123456");
str = "9867578";
CString strval = str. SpanExcluding (strdigital);
MessageBox (Strval);

Strval= "98"

No match found to ' 6 ', return ' 98 '

Judging whether a string is all numbers, you can write this

BOOL isdigital (CString str)

{

Return STR==STR. SpanIncluding ("0123456789");

}

The usage of spanincluding and spanexcluding in CString

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.