Delete a specific character

Source: Internet
Author: User

Thinking path: Use the character as the subscript of the array (the C language allows ing the character into an integer to act as the subscript of the array) or as the key word of the hash table.

Viod removechars (char STR [], char remove [])
Note: All characters in remove must be removed from Str.

For example, if STR: "Battle of the vowels: Hawaii vs. Grozny ",

Remove: "aeiou ",

Result: STR is converted to "bttl F th vwls: HW vs. grzny ".

 

# Include <iostream>
# Include <string. h>
Using namespace STD;
Void removechars (char STR [], char remove []);
Void main ()
{
Char STR [50], remove [10];
Cout <"Enter the main string :";
Cin. Getline (STR, 50 );
Cout <"Enter the character set to be deleted :";
Cin> remove;
Cout <"output STR after deleting a specific character set :";
Removechars (STR, remove );
Cout <STR <Endl;
}

Void removechars (char STR [], char remove [])
{
Int SRC, DST, removearray [1, 256];
For (src = 0; SRC <256; SRC ++)
{
Removearray [SRC] = 0;
}
Src = 0;
While (remove [SRC])
{
Removearray [remove [SRC] = 1;
SRC ++;
}
 
Src = DST = 0;
Do
{
If (! Removearray [STR [SRC])
STR [DST ++] = STR [SRC];
} While (STR [SRC ++]);
}

 

 

 

 

(2)

 

# Include <iostream>
# Include <vector>
Using namespace STD;

Bool find (char C, STD: vector <char> & substr)
{
STD: vector <char >:: iterator ITER;
For (iter = substr. Begin (); iter! = Substr. End (); ++ ITER)
If (* iter = C)
Return true;
Return false;
}

Void strdeal (char * STR, char * substr)
{
Char strtemp [1000];
STD: vector <char> substr;
Int J = 0;
While (substr [J])
{
Substr. push_back (substr [J]);
J ++;
}
J = 0;
Int I = 0;
While (STR [J])
{
If (! Find (STR [J], substr ))
Strtemp [I ++] = STR [J];
J ++;
}
Strtemp [I] = '/0 ';
Cout <strtemp <Endl;
}

Int main ()
{
Char STR [1000];
Cin. Getline (STR, 1000 );
Strdeal (STR, "aeiou ");
Return 0;
}

Related Article

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.