remove common characters (regex)

Topic description

Enter two strings and delete all characters in the second string from the first string. For example, enter "They are students." and "aeiou", the first string after deletion becomes "Thy r stdnts."

Enter description:

Each test input contains 2 strings

Output description:

output the removed string
Example 1

enter

They are students. aeiou

output

Thy r stdnts.

1  /** 
2  * 
 3  * delete common characters
 4  * 1, split the string according to regular expression
 5          2, concatenate the string
 6  * @author Dell
 7  *
 8   */ 
9  import java.util.Scanner;
 10  public  class Main {
 11  public  static  void main(String[] args) {
 12          Scanner sc = new Scanner(System.in);
 13          String str1 = sc.nextLine();
 14          String str2 = sc.nextLine();
 15         String matching = "["+str2+"]"; // regular expression 
16          String []strs = str1.split(matching); // split string according to regular expression 
17          String res = "" ;
 18          for ( int i = 0; i < strs.length; i++) { // Concatenate strings 
19              res+= strs[i];
 20          }
 21          System.out.println(res);
 22      }
 23 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325157360&siteId=291194637