Delete character substrings

Source: Internet
Author: User

1. Brief Introduction

Removes all characters that have occurred in another string from one string. It is basically relatively simple. It mainly refers to placing the characters to be saved in the proper position, releasing the characters to be deleted, and processing the characters '\ 0.

2. Code

# Include <iostream>
Using namespace STD;

Bool find (const char * cs, const char ch ){
Assert (CS! = 0 );
While ('\ 0 '! = * Cs & Ch! = * Cs)
CS ++;
If ('\ 0' = * cs)
Return false;
Else
Return true;
}

Void delete_str (char * STR, const char * cs ){
Assert (STR! = 0 & CS! = 0 );
Char * result = str;
Int gap, len; gap = len = 0;
While (* str! = '\ 0 '){
If (find (cs, * str) {// discard this character
Gap ++; // number of characters deleted
}
Else {// save this character
Len ++; // number of reserved characters
* (Str-gap) = * str;
}
Str ++;
}
* (Result + len) = '\ 0'; //' \ 0' for processing
For (int I = 0; I <gap; I ++) // release the memory
Delete (result + Len + I + 1 );
}

Int main (){
Char STR [100] = {'h', 'E', 'l', 'l', 'O', ',', 'w', 'O ', 'R', 'l', 'D ','. '};
Char CS [5] = "Lo ";
Cout <STR <Endl;
Cout <CS <Endl;
Delete_str (STR, CS );
Cout <STR <Endl;
System ("pause ");
Return 0 ;}

3. Remarks

It is difficult to test basic C ++ programming.

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.